Skip to content

Instantly share code, notes, and snippets.

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