Reputation: 13
const array1 = [2,5,10];
const arr10 = function(arr) { arr.map(x => x * 10); };
console.log(arr10(array1));
arr10(array1); should return an array with every number inside array1 * 10. I don't understand why I get undefined.
Upvotes: 0
Views: 75
Reputation: 22886
The confusion might be related to the arrow function cases where return
statement can be ommited:
const arr10 = (arr) => arr.map(x => x * 10);
console.log( arr10( [1, 2, 3] ) );
Upvotes: 1
Reputation:
You don't return anything in your function.
const arr10 = function (arr) {return arr.map((x) => {return x * 10;});}
Upvotes: 0
Reputation: 7368
you have to add return in function:
const array1 = [2,5,10];
const arr10 = function(arr) { return arr.map(x => x * 10); };
console.log(arr10(array1));
Upvotes: 0
Reputation: 12970
You aren't returning anything in your function:
const arr10 = function(arr) { return arr.map(x => x * 10); };
Upvotes: 0