Package Exports
- array-find-predecessor
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (array-find-predecessor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
array-find-predecessor
Find a predecessor value of the array that should be chosen when a given index is deleted
import arrayFindPredecessor from 'array-find-predecessor';
const array = ['foo', 'bar', 'baz'];
arrayFindPredecessor(array, 1); //=> 'foo'
arrayFindPredecessor(array, 2); //=> 'bar'
arrayFindPredecessor(array, 0); //=> 'bar'
Installation
npm
npm install array-find-predecessor
bower
bower install array-find-predecessor
API
arrayFindPredecessor(array, index)
array: Array
(non-empty array)
index: Number
(index of the array assumed to be deleted)
Return: Number
or null
Essentially, it returns an array value one index before the given index
.
value: A B C
deleted: ^
substitute: ^
arrayFindPredecessor(['A', 'B', 'C'], 1); //=> 'A'
If index
is 0
, it returns the successor value because the first element has no predecessor elements.
value: A B C
deleted: ^
substitute: ^
arrayFindPredecessor(['A', 'B', 'C'], 0); //=> 'B'
If the array includes only a single value, it returns null
because no value exists except for the deleted value.
value: A
deleted: ^
substitute: (none)
arrayFindPredecessor(['A'], 0); //=> null
License
Copyright (c) 2016 Shinnosuke Watanabe
Licensed under the MIT License.