bracketing v1.0.2
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.
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 rightAPI
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 ofsequence. It must return abooleanvalue indicating pass or fail of the two elements. Has the following signatureleft- the left valueright- the right value
sequence- astringorarrayto 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.