What does the following code return?
new Set([1,1,2,2,3,4]) // {1, 2, 3, 4}
What does the following code return?
[...new Set("referee")].join("") // "ref"
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);
// {1: true, 2: true, 3: true, 1: false, 2: false, 3: false}
Write a function called hasDuplicate which accepts an array and returns true or false if that array contains a duplicate
const hasDuplicate = array => new Set(array).size !== arr.length
hasDuplicate([1,3,2,1]) // true
hasDuplicate([1,5,-1,4]) // false
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.
const vowelCount = string => {
const out = new Map();
const vowels = new Set(["a", "e", "i", "o", "u"]);
for (let letter of string.toLowercase()) {
if (vowels.has(letter)) {
if (out.has(letter)) {
out.set(letter, out.get(letter) + 1);
} else {
out.set(letter, 1);
}
}
}
}
vowelCount('awesome') // Map { 'a' => 1, 'e' => 2, 'o' => 1 }
vowelCount('Colt') // Map { 'o' => 1 }
See Our solution.