1.3.1 • Published 8 years ago
array-map-sorted v1.3.1
array-map-sorted
Compare two sorted arrays, and map the items of the first map to matched ones.
Install
$ npm install array-map-sortedUsage
import map from 'array-map-sorted'
const args = [
[
// 1 matches 4
1,
// 2 starts to match from 5 (4 has already been matched), and no matches
2,
// 3 starts to match from 5, and matches 9
3
],
[4, 5, 7, 9],
(a, b) => b % a === 0
]
map(...args)
// [4, undefined, 9]
map(...args, 0)
// [4, 0, 9]
map(...args, 0, (datum, rel) => datum + rel)
// [5, 0, 12]map(data, relative, matcher, defaultValue = undefined, mapper)
- data
Array<datum>the array to be mapped - relative
Array<rel>which each datum ofdatawill be matched with. - matcher
function(datum, rel, datum_i, rel_i): booleanthe matcher function - defaultValue
any=undefinedif there is no match, the datum will be mapped todefaultValue - mapper
function(datum, rel, datum_i, rel_i): anyif there is a match,mapperreturns the value which the datum to be mapped into. By default,mapperis(datum, rel) => rel.
Returns Array
License
MIT