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:
1.1 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | import {
|
---|
| 2 | values,
|
---|
| 3 | both,
|
---|
| 4 | complement,
|
---|
| 5 | pipe,
|
---|
| 6 | converge,
|
---|
| 7 | identical,
|
---|
| 8 | length,
|
---|
| 9 | } from 'ramda';
|
---|
| 10 |
|
---|
| 11 | import isArray from './isArray';
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * Checks if input value is a sparse Array.
|
---|
| 15 | * An array with at least one "empty slot" in it is often called a "sparse array."
|
---|
| 16 | * Empty slot doesn't mean that the slot contains `null` or `undefined` values,
|
---|
| 17 | * but rather that the slots don't exist.
|
---|
| 18 | *
|
---|
| 19 | * @func isSparseArray
|
---|
| 20 | * @memberOf RA
|
---|
| 21 | * @since {@link https://char0n.github.io/ramda-adjunct/2.20.0|v2.20.0}
|
---|
| 22 | * @category Type
|
---|
| 23 | * @sig * -> Boolean
|
---|
| 24 | * @param {*} list The list to test
|
---|
| 25 | * @return {boolean}
|
---|
| 26 | * @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}
|
---|
| 27 | * @example
|
---|
| 28 | *
|
---|
| 29 | * RA.isSparseArray(new Array(3)); // => true
|
---|
| 30 | * RA.isSparseArray([1,,3]); // => true
|
---|
| 31 | *
|
---|
| 32 | * const list = [1, 2, 3];
|
---|
| 33 | * delete list[1];
|
---|
| 34 | * RA.isSparseArray(list); // => true
|
---|
| 35 | *
|
---|
| 36 | * RA.isSparseArray([1, 2, 3]); // => false
|
---|
| 37 | */
|
---|
| 38 | const isSparseArray = both(
|
---|
| 39 | isArray,
|
---|
| 40 | converge(complement(identical), [pipe(values, length), length])
|
---|
| 41 | );
|
---|
| 42 |
|
---|
| 43 | export default isSparseArray;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.