Today, I am going to use the built-in .map() method on arrays to solve all of these problems
These assignments are from https://coursework.vschool.io/array-map-exercises/.
map() method documents: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
1) Make an array of numbers that are doubles of the first array.
function doubleNumbers(arr){
// your code here
}
console.log(doubleNumbers([2, 5, 100])); // [4, 10, 200]
Answer:
function doubleNumbers(arr){
let doubleArr = arr.map(x=>x*2);
return doubleArr;
}
console.log(doubleNumbers([2, 5, 100]))
2) Take an array of numbers and make them strings
function stringItUp(arr){
// your code here
}
console.log(stringItUp([2, 5, 100])); // ["2", "5", "100"]
Answer:
function stringItUp(arr)