Find a predecessor value of the array that should be chosen when a given array index is deleted
npm install array-find-predecessor





Find a predecessor value of the array that should be chosen when a given index is deleted
``javascript
import arrayFindPredecessor from 'array-find-predecessor';
const array = ['foo', 'bar', 'baz'];
arrayFindPredecessor(array, 1); //=> 'foo'
arrayFindPredecessor(array, 2); //=> 'bar'
arrayFindPredecessor(array, 0); //=> 'bar'
`
``
npm install array-find-predecessor
``
bower install array-find-predecessor
array: Array (non-empty array) Number
index: (index of the array assumed to be deleted) Number
Return: or null
Essentially, it returns an array value one index before the given index.
``
value: A B C
deleted: ^
substitute: ^
`javascript`
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: ^
`javascript`
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)
`javascript``
arrayFindPredecessor(['A'], 0); //=> null
Copyright (c) 2016 Shinnosuke Watanabe
Licensed under the MIT License.