1 | import { values, both, complement, pipe, converge, identical, length } from 'ramda';
|
---|
2 | import isArray from './isArray';
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * Checks if input value is a sparse Array.
|
---|
6 | * An array with at least one "empty slot" in it is often called a "sparse array."
|
---|
7 | * Empty slot doesn't mean that the slot contains `null` or `undefined` values,
|
---|
8 | * but rather that the slots don't exist.
|
---|
9 | *
|
---|
10 | * @func isSparseArray
|
---|
11 | * @memberOf RA
|
---|
12 | * @since {@link https://char0n.github.io/ramda-adjunct/2.20.0|v2.20.0}
|
---|
13 | * @category Type
|
---|
14 | * @sig * -> Boolean
|
---|
15 | * @param {*} list The list to test
|
---|
16 | * @return {boolean}
|
---|
17 | * @see {@link https://github.com/getify/You-Dont-Know-JS/blob/f0d591b6502c080b92e18fc470432af8144db610/types%20%26%20grammar/ch3.md#array|Sparse Arrays}, {@link RA.isArray|isArray}
|
---|
18 | * @example
|
---|
19 | *
|
---|
20 | * RA.isSparseArray(new Array(3)); // => true
|
---|
21 | * RA.isSparseArray([1,,3]); // => true
|
---|
22 | *
|
---|
23 | * const list = [1, 2, 3];
|
---|
24 | * delete list[1];
|
---|
25 | * RA.isSparseArray(list); // => true
|
---|
26 | *
|
---|
27 | * RA.isSparseArray([1, 2, 3]); // => false
|
---|
28 | */
|
---|
29 | var isSparseArray = both(isArray, converge(complement(identical), [pipe(values, length), length]));
|
---|
30 | export default isSparseArray; |
---|