Created
April 6, 2019 19:43
-
-
Save winarcooo/9c31879eeeedbaf0d1deb251759042e3 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
function changeValue(arr) { | |
return function fromIndex(arrIndex) { | |
return function withValue(newValue) { | |
return arr.map(function(arr, index){ | |
if (index == arrIndex) { | |
return newValue | |
} | |
return arr | |
}) | |
} | |
} | |
} | |
const changeValue = arr => arrIndex => newValue => { | |
return arr.map((arr, index) => { | |
if (index == arrIndex) { | |
return newValue | |
} | |
return arr | |
}) | |
} | |
var array = [2,3,5] | |
var newArray = changeValue(array)(0)(7) | |
console.log(newArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment