Skip to content

Instantly share code, notes, and snippets.

@omarbenmegdoul
Last active March 27, 2021 01:04
Show Gist options
  • Save omarbenmegdoul/be825f79801fdd60ea65a5e3a0cc8cc7 to your computer and use it in GitHub Desktop.
Save omarbenmegdoul/be825f79801fdd60ea65a5e3a0cc8cc7 to your computer and use it in GitHub Desktop.
someArray.map(callback) explainer
//This program will take an array of numbers and return an array of those numbers to the power of 3.
//map is used for transforming each element of an array to receive a new array.
//So there is a final array where the results have to be stored.
//We can convert translate the function to the arrow function shorthand to save space
let baseArray = [1,2,3,4,5,6,7,8,9,0];
finalArray = baseArray.map(
num => num ** 3 //what goes on the other side of the arrow is what would go after "return" in the old function
)
//console.log(finalArray) //to see the output, you'd have to un-comment this line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment