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:
929 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | import { pipe, intersection, isEmpty, curryN } from 'ramda';
|
---|
| 2 |
|
---|
| 3 | import isNotEmpty from './isNotEmpty';
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * Returns true if two lists have at least one element common to both lists.
|
---|
| 7 | *
|
---|
| 8 | * @func overlaps
|
---|
| 9 | * @memberOf RA
|
---|
| 10 | * @category Relation
|
---|
| 11 | * @since {@link https://char0n.github.io/ramda-adjunct/2.30.0|v2.30.0}
|
---|
| 12 | * @sig [a] -> [a] -> Boolean
|
---|
| 13 | * @param {Array} list1 The first list
|
---|
| 14 | * @param {Array} list2 The second list
|
---|
| 15 | * @return {boolean} True if two lists have at least one element common to both lists
|
---|
| 16 | * @example
|
---|
| 17 | *
|
---|
| 18 | * RA.overlaps(['-v', '--verbose'], ['node', 'script.js', '-v']); //=> true
|
---|
| 19 | * RA.overlaps(['-v', '--verbose'], []); //=> false
|
---|
| 20 | * RA.overlaps([1, 2, 3], [3, 4, 5]); //=> true
|
---|
| 21 | * RA.overlaps([1, 2, 3], [4, 5]); //=> false
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 | const overlaps = curryN(2, (list1, list2) => {
|
---|
| 25 | if (isEmpty(list1)) {
|
---|
| 26 | return true;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | return pipe(intersection, isNotEmpty)(list1, list2);
|
---|
| 30 | });
|
---|
| 31 |
|
---|
| 32 | export default overlaps;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.