Socket
Socket
Sign inDemoInstall

array-prefer

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    array-prefer

return array sorted by boolean priority function.


Version published
Weekly downloads
2
Maintainers
1
Install size
5.42 kB
Created
Weekly downloads
 

Readme

Source

array-prefer

Build Status Coverage Status

Returns a copy of the input array, with preferred items moved to the front.

Installation

npm i array-prefer -S

Dependencies

None. Suitable for usage on nodejs or on the browser, via browserify/webpack.

Initialization

const arrayPrefer = require('array-prefer');

Usage

const outArray = arrayPrefer(inArray, hasPriority, limit);

inArray an input array of items (required)

hasPriority a function that returns truthy or falsey on items, indicating items that have priority (required)

limit an integer indicating the maximum number of items that may have priority (optional)

outArray a copy of inArray with items having priority moved to the front (lowest indexes). Except for moving some items to the front of the array, the order of items is otherwise preserved.

Examples


arrayPrefer([3,1,2], (x)=>(x<3)) // --> [1,2,3]

arrayPrefer([3,1,2], (x)=>(x<3), 0) // -->  [3,1,2]

arrayPrefer([3,1,2], (x)=>(x<3), 1) // --> [1,3,2]

arrayPrefer([3,1,2], (x)=>(x<3), 2) // --> [1,2,3]

Copyright 2019 Paul Brewer, Economic and Financial Technology Consulting LLC

License

MIT

Keywords

FAQs

Last updated on 13 Feb 2019

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc