Overview
Implement square(array) — returns a new array where each element is squared.
Examples
square([1,2,3]); // [1,4,9] square([-2,0,3]); // [4,0,9]
Solution
Reveal solution
function square(array) {
return array.map(x => x * x);
}array-prototype-square.js
Array.prototype.square
easycodingJavaScriptArrays
Overview
Implement square(array) — returns a new array where each element is squared.
Examples
square([1,2,3]); // [1,4,9] square([-2,0,3]); // [4,0,9]
Solution
Reveal solution
function square(array) {
return array.map(x => x * x);
}NameTopicDifficulty
103 of 103 problems