Skip to content

Instantly share code, notes, and snippets.

@pramendra
Created June 19, 2020 10:26
Show Gist options
  • Save pramendra/342a775a39f5053395e2c44d3ff303bd to your computer and use it in GitHub Desktop.
Save pramendra/342a775a39f5053395e2c44d3ff303bd to your computer and use it in GitHub Desktop.
getFirstThreeFromArray using Ramda
// 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