Giter VIP home page Giter VIP logo

node-array-map-sorted's Introduction

Build Status Coverage

array-map-sorted

Compare two sorted arrays, and map the items of the first map to matched ones.

Install

$ npm install array-map-sorted

Usage

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 of data will be matched with.
  • matcher function(datum, rel, datum_i, rel_i): boolean the matcher function
  • defaultValue any=undefined if there is no match, the datum will be mapped to defaultValue
  • mapper function(datum, rel, datum_i, rel_i): any if there is a match, mapper returns the value which the datum to be mapped into. By default, mapper is (datum, rel) => rel.

Returns Array

License

MIT

node-array-map-sorted's People

Contributors

kaelzhang avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.