Skip to content

Instantly share code, notes, and snippets.

@tripdog
Created June 17, 2021 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripdog/680ef04c3c4da984adc76fa094ffdf95 to your computer and use it in GitHub Desktop.
Save tripdog/680ef04c3c4da984adc76fa094ffdf95 to your computer and use it in GitHub Desktop.
Create a function that returns the square of each number in an array.

Create a function that returns the square of each number in an array.

function squareNums(arr) {
    const newArray = []
    for (let i = 0; i < arr.length; i++){
     newArray.push(arr[i] * arr[i]);
    }
    return newArray
}
console.log(squareNums([2,4,6,8,10]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment