-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
Showing
4 changed files
with
166 additions
and
1 deletion.
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
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,54 @@ | ||
const persons = [ | ||
{name:"John", age:70}, | ||
{name:"Kane", age:5}, | ||
{name:"Jack", age:50}, | ||
{name:"Rambo", age:15} | ||
]; | ||
|
||
// Callback function to categorize people based on age | ||
function callbackFunc({ age }) { | ||
if(age >= 60) { | ||
return "senior"; | ||
} else if(age > 17 && age < 60) { | ||
return "adult"; | ||
} | ||
else { | ||
return "kid"; | ||
} | ||
} | ||
|
||
//Object groupBy | ||
const result = Object.groupBy(persons, callbackFunc); | ||
|
||
console.log("Kids: "); | ||
for (let [x,y] of result.kid.entries()) { | ||
console.log(y.name + " " + y.age); | ||
} | ||
|
||
console.log("Adults: "); | ||
for (let [x,y] of result.adult.entries()) { | ||
console.log(y.name + " " + y.age); | ||
} | ||
|
||
console.log("Seniors: "); | ||
for (let [x,y] of result.senior.entries()) { | ||
console.log(y.name + " " + y.age); | ||
} | ||
|
||
//Map groupBy | ||
const result1 = Map.groupBy(persons, callbackFunc); | ||
|
||
console.log("Kids: "); | ||
for (let x of result1.get("kid")) { | ||
console.log(x.name + " " + x.age); | ||
} | ||
|
||
console.log("Adults: "); | ||
for (let x of result1.get("adult")) { | ||
console.log(x.name + " " + x.age); | ||
} | ||
|
||
console.log("Seniors: "); | ||
for (let x of result1.get("senior")) { | ||
console.log(x.name + " " + x.age); | ||
} |
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,17 @@ | ||
const str1 = "Hello World \uD815"; | ||
const str2 = "Welcome to ES2024"; | ||
const str3 = "Welcome to ES2024 😀"; | ||
|
||
console.log(str1.isWellFormed()); // false | ||
console.log(str2.isWellFormed()); // true | ||
console.log(str2.isWellFormed()); // true | ||
|
||
console.log(str1.toWellFormed()); // Hello World � | ||
console.log(str2.toWellFormed()); // Welcome to ES2024 | ||
|
||
const url = "https://somedomain.com/query=\uD423"; | ||
try { | ||
console.log(encodeURI(url.toWellFormed())); // https://somedomain.com/query=%ED%90%A3 | ||
} catch (e) { | ||
console.log('Error:', e.message); | ||
} |
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,6 @@ | ||
const arrayBuffer = new SharedArrayBuffer(1024); | ||
const arr = new Int32Array(arrayBuffer); | ||
|
||
Atomics.waitAsync(arr, 0 , 0 , 500); // { async: true, value: Promise {<pending>}} | ||
|
||
Atomics.notify(arr, 0); // { async: true, value: Promise {<fulfilled>: 'ok'} } |