mapSquares

Easy · Functional Programming Concepts · 2 test cases

Given an array of numbers, return a new array where each number is squared. Use the functional programming method 'map'.

Examples

mapSquares([1, 2, 3, 4]) → [1, 4, 9, 16]
mapSquares([5, 6, 7]) → [25, 36, 49]

Starter code

function mapSquares(arr) {

}

Complexity of the optimal solution

Time O(n), space O(n). The `map` method iterates over each of the n elements in the input array to create a new array of the same size. Therefore, both the time taken and the space required for the new array are proportional to n.

Solve mapSquares in the browser