Skip to content

Instantly share code, notes, and snippets.

@winarcooo
Created April 6, 2019 19:43
Show Gist options
  • Save winarcooo/9c31879eeeedbaf0d1deb251759042e3 to your computer and use it in GitHub Desktop.
Save winarcooo/9c31879eeeedbaf0d1deb251759042e3 to your computer and use it in GitHub Desktop.
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