Created
June 19, 2020 10:26
-
-
Save pramendra/342a775a39f5053395e2c44d3ff303bd to your computer and use it in GitHub Desktop.
getFirstThreeFromArray using Ramda
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
// const { compose, defaultTo, equals, map, slice } = R; | |
const slice2DArray = (slice) => compose(defaultTo([]), map(slice)); | |
const getFirstThreeFromArray = slice2DArray(slice(0, 3)); | |
const input_data = [ | |
["a", "b", "c", "d"], | |
["a", "b", "c", "d"], | |
["a", "b", "c", "d"], | |
["a", "b"], | |
["x", "y", "z", "z1"], | |
[], | |
]; | |
const output_data = [ | |
["a", "b", "c"], | |
["a", "b", "c"], | |
["a", "b", "c"], | |
["a", "b"], | |
["x", "y", "z"], | |
[], | |
]; | |
// test | |
equals(getFirstThreeFromArray(input_data), output_data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment