Last active
November 2, 2017 20:35
-
-
Save ivan-nikitovic/ba2983f68b6c92a3a88aa4279074962f to your computer and use it in GitHub Desktop.
Redux - Map array with conditional modification
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
const map = array => ({ | |
when: condition => ({ | |
then: modification => array.map( | |
(item, index, collection) => condition(item, index, collection) ? modification(item, index, collection) : item, | |
), | |
}), | |
}); | |
map([1, 2, 3]).when(number => number > 1).then(number => number * 2) // [1, 4, 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment