doubleArrayValues

Easy · Loops and Iterations · 3 test cases

Given an array of numbers, create and return a new array where each value is doubled.

Examples

doubleArrayValues([1, 2, 3]) → [2, 4, 6]
doubleArrayValues([0, -5, 10]) → [0, -10, 20]

Starter code

function doubleArrayValues(arr) {

}

Complexity of the optimal solution

Time O(n), space O(n). The function iterates through the original array of size n once. It creates a new array of the same size. Therefore, both time and space complexity are linear.

Solve doubleArrayValues in the browser