Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bracketing

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bracketing

Function to efficiently traverse large strings or arrays and run a predicate on adjacent values.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Bracketing

bracketing is a small utility function to effeciantly walk and compare consecutive elements in an array or string and extract the longest sub array that fulfills this predicate. It is essentially two managed array pointers to traverse an array with the bare minimum number of comparisons. It will return the longest sequence that satisfies the supplied predicate function.

Current Version Build Status

Useage

These following examples demonstrate some basic usage and should give you a better idea what bracketing is all about

const bracketing = require('bracketing');

let result;

result = bracketing((left, right) => right > left, [1, 2, 3, 0, 5, 6, 7, 8, 100]);
// result equals [0, 5, 6, 7, 8, 100] because it is the longest sub array where the right value is greater than the left
result = bracketing((left, right) => left === right, 'aaaaaabbbbbccdeeeeeeeeeee');
// result equals "eeeeeeeeeee" because it is the longest substring where each character equals the one to the right

API

bracketing(predicate, sequence)

Returns the result of running the predicate against sequence. The result is either a string or array, matching the type of sequence.

  • predicate - a function to run against the elements of sequence. It must return a boolean value indicating pass or fail of the two elements. Has the following signature
    • left - the left value
    • right - the right value
  • sequence - a string or array to traverse.

Browser Usage

There is a UMD build provided in the "dist" folder. bracketing should have no issues working in a browser context. The only potential "got ya" is that accessing a string using bracket notation, which this module does, will not work in Internet Explorer 7.

FAQs

Package last updated on 11 Apr 2018

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc