Last active
November 8, 2015 19:52
-
-
Save kuanyingchou/dc46c18cad771e1272c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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