-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6bd984
commit ab94b3f
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Write a function that determines and returns the UTF-16 string value of a | ||
// string passed in as an argument. The UTF-16 string value is the sum of the | ||
// UTF-16 values of every character in the string. (You may use | ||
// String.prototype.charCodeAt() to determine the UTF-16 value of a character.) | ||
|
||
const utf16Value = (string1) => { | ||
let sum = 0; | ||
for (const element of string1) { | ||
sum += element.charCodeAt(element); | ||
} | ||
return sum; | ||
}; | ||
|
||
console.log(utf16Value('Four score')); // 984 | ||
console.log(utf16Value('Launch School')); // 1251 | ||
console.log(utf16Value('a')); // 97 | ||
console.log(utf16Value('')); // 0 | ||
|
||
const OMEGA = "\u03A9"; // UTF-16 character 'Ω' (omega) | ||
console.log(utf16Value(OMEGA)); |