Created
May 23, 2016 11:46
-
-
Save iofjuupasli/dc251f17030d88603e71f86f3265c19d to your computer and use it in GitHub Desktop.
This file contains 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
myData.map(fixName); | |
function fixName(person) { | |
return Object.assign({}, person, { | |
name: person.name.replace(/John/g, "Ben") | |
}); | |
} | |
// inline function | |
myData.map(function fixName(person) { | |
return Object.assign({}, person, { | |
name: person.name.replace(/John/g, "Ben") | |
}); | |
}); | |
// use R.replace instead String.prototype.replace | |
myData.map(function (person) { | |
return Object.assign({}, person, { | |
name: R.replace(/John/g, "Ben")(person.name) | |
}); | |
}); | |
// Use | |
// R.evolve({prop: fn})(item) | |
// instead | |
// Object.assign({}, item, {prop: fn(item['prop'])}) | |
myData.map(function (person) { | |
return R.evolve({ | |
name: R.replace(/John/g, "Ben") | |
})(person); | |
}); | |
// f(x => u(x)) == f(u) | |
myData.map(R.evolve({ | |
name: R.replace(/John/g, "Ben") | |
})); | |
// use R.map instead Array.prototype.map | |
R.map(R.evolve({ | |
name: R.replace(/John/g, "Ben") | |
}))(myData); | |
// or separately | |
var fixName = R.replace(/John/g, "Ben"); | |
var fixPersonName = R.evolve({ name: fixName }); | |
var fixNames = R.map(fixPersonName); | |
var fixedData = fixNames(myData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment