source: node_modules/ramda-adjunct/src/skipTake.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 755 bytes
Line 
1import {
2 curry,
3 addIndex,
4 filter,
5 pipe,
6 modulo,
7 identical,
8 nthArg,
9 __,
10} from 'ramda';
11
12/**
13 * When given a number n and an array, returns an array containing every nth element.
14 *
15 * @func skipTake
16 * @memberOf RA
17 * @category List
18 * @since {@link https://char0n.github.io/ramda-adjunct/2.26.0|v2.26.0}
19 * @sig Number -> [a] -> [a]
20 * @param {number} the nth element to extract
21 * @param {Array} value the input array
22 * @return {Array} An array containing every nth element
23 * @example
24 *
25 * RA.skipTake(2, [1,2,3,4]) //=> [1, 3]
26 * RA.skipTake(3, R.range(0, 20)); //=> [0, 3, 6, 9, 12, 15, 18]
27 */
28
29const skipTake = curry((n, list) =>
30 addIndex(filter)(pipe(nthArg(1), modulo(__, n), identical(0)))(list)
31);
32
33export default skipTake;
Note: See TracBrowser for help on using the repository browser.