Skip to content

Instantly share code, notes, and snippets.

@kuanyingchou
Created November 8, 2015 19:01
Show Gist options
  • Save kuanyingchou/fd7c11ab2c45d53799eb to your computer and use it in GitHub Desktop.
Save kuanyingchou/fd7c11ab2c45d53799eb to your computer and use it in GitHub Desktop.
let a = [1, 2, 3, 4, 5];
let index = 2;
let inc = i => i+1;
let dec = i => i-1;
let b = [...a.slice(0, index).map(inc), dec(a[index]), ...a.slice(index+1).map(inc)];
console.log(`a=[${a}]`);
console.log(`b=[${b}]`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment