Maps Practice Quiz¶
Question 1¶
maps-quiz1: What would the following code print?:
let wordArray = ["computer", "science", "thirty"];
let myMap = new Map();
for (let i = 0; i < wordArray.length; i++) {
myMap.set(wordArray[i], wordArray[i].length);
}
console.log(myMap.get("science"));
Question 2¶
maps-quiz2: What would the following code print?:
let wordArray = ["computer", "science", "thirty"];
let myMap = new Map();
for (let i = 0; i < wordArray.length; i++) {
myMap.set(wordArray[i], wordArray[i].length);
}
console.log(myMap.get("computer"));
Question 3¶
maps-quiz3: What would the following code print?:
function mapChanger(someMap){
if (someMap.has("a")) {
someMap.set("b", someMap.get("a"));
}
someMap.delete("c");
return someMap;
}
let myMap = new Map();
myMap.set("a", "happy");
myMap.set("b", "sad");
myMap.set("c", "excited");
myMap = mapChanger(myMap);
console.log(myMap.get("b"));
Question 4¶
maps-quiz4: What would the following code print?:
function mapChanger(someMap){
if (someMap.has("a")) {
someMap.set("b", someMap.get("a"));
}
someMap.delete("c");
return someMap;
}
let myMap = new Map();
myMap.set("b", "sad");
myMap.set("c", "excited");
myMap = mapChanger(myMap);
console.log(myMap.get("b"));
Question 5¶
maps-quiz5: What would the following code print?:
function mapChanger(someMap){
if (someMap.has("a")) {
someMap.set("b", someMap.get("a"));
}
someMap.delete("c");
return someMap;
}
let myMap = new Map();
myMap.set("b", "sad");
myMap.set("c", "excited");
myMap = mapChanger(myMap);
console.log(myMap.get("c"));
Question 6¶
maps-quiz6: What would the following code print?:
function otherMapChanger(someMap){
if (someMap.has("a") && someMap.has("b")) {
let combined = someMap.get("a") + someMap.get("b");
someMap.set("ab", combined);
}
return someMap;
}
let myMap = new Map();
myMap.set("a", "happy");
myMap.set("b", "sad");
myMap.set("c", "excited");
myMap = otherMapChanger(myMap);
console.log(myMap.get("ab"));
Question 7¶
maps-quiz7: What would the following code print?:
function otherMapChanger(someMap){
if (someMap.has("a") && someMap.has("b")) {
let combined = someMap.get("a") + someMap.get("b");
someMap.set("ab", combined);
}
return someMap;
}
let myMap = new Map();
myMap.set("b", "sad");
myMap.set("c", "excited");
myMap = otherMapChanger(myMap);
console.log(myMap.get("ab"));
Question 8¶
Solve the mapAB5 CodingJS array problem.
Question 9¶
Solve the pairs2 CodingJS array problem.