What does the following code return?
new Set([1,1,2,2,3,4])
new Set([1,1,2,2,3,4])
- returns
Set(4) { 1, 2, 3, 4 }
- returns
What does the following code return?
[...new Set("referee")].join("")
[...new Set("referee")].join("")
- returns
"ref"
- returns
What does the Map m look like after running the following code?
let m = new Map();
m.set([1,2,3], true);
m.set([1,2,3], false);
m
- returns
Map(2)ย {Array(3) => true, Array(3) => false}
- returns
Write a function called hasDuplicate which accepts an array and returns true or false if that array contains a duplicate
hasDuplicate([1,3,2,1]) // true
hasDuplicate([1,5,-1,4]) // false
const hasDuplicate = a => new Set(a).size !== a.length;
Write a function called vowelCount which accepts a string and returns a map where the keys are numbers and the values are the count of the vowels in the string.
vowelCount('awesome') // Map { 'a' => 1, 'e' => 2, 'o' => 1 }
vowelCount('Colt') // Map { 'o' => 1 }
const vowelCount = str => str.toLowerCase().split("").reduce((a, v) => {
if ("aeiou".includes(v))
a.has(v) ? a.set(v, a.get(v) + 1) : a.set(v, 1);
return a;
}, new Map());