New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

single-pass

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

single-pass

## do it all in a single-pass

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

single-pass

do it all in a single-pass

map

    import { map } from 'single-pass';

    const [mulOne, mulTwo, mulThree] = map(
      [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
      (n) => n * 1,
      (n) => n * 2,
      (n) => n * 3
    );

    console.log(one); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    console.log(two); // [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
    console.log(three); // [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]

filter

    import { filter } from 'single-pass';

    const [odds, evens, divisibleByThree] = filter(
      [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
      (n) => n % 2 !== 0,
      (n) => n % 2 === 0,
      (n) => n % 3 === 0
    );
    
    console.log(odds); // [1, 3, 5, 7, 9]
    console.log(evens); // [2, 4, 6, 8, 10]
    console.log(divisibleByThree); // [3, 6, 9]

find

    import { find } from 'single-pass';

    const [one, two, twenty] = find(
      [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
      (n) => n === 1,
      (n) => n === 2,
      (n) => n === 20
    );
    
    console.log(one); // 1
    console.log(two); // 2
    console.log(twenty); // undefined

findIndex

    import { findIndex } from 'single-pass';

    const [one, two, twenty] = findIndex(
      [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
      (n) => n === 1,
      (n) => n === 2,
      (n) => n === 20
    );
    
    console.log(one); // 0
    console.log(two); // 1
    console.log(twenty); // -1

Benchmarks

Benchmarks on an array with 1,000,000 items doing 1000 passes

Functionn-passessingle-pass
Filter1267ms2646ms

Keywords

single-pass

FAQs

Package last updated on 28 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts