Skip to content

Instantly share code, notes, and snippets.

@h09shais
Created June 21, 2019 13:44
Show Gist options
  • Save h09shais/09b73ee3da885565de45f83a4a4739e5 to your computer and use it in GitHub Desktop.
Save h09shais/09b73ee3da885565de45f83a4a4739e5 to your computer and use it in GitHub Desktop.
JavaScript map fun
[1, 2, 3].map(x => x + 1)
> (3) [2, 3, 4]
const add = (x) => x + 1;
const substract = (x) => x - 1;
function mapArray(values, func) { return values.map(func); }
mapArray([1, 2, 3], add)
> (3) [2, 3, 4]
mapArray([1, 2, 3], substract)
> (3) [0, 1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment