1. arrayslicer
Node.JS module that implements an optimized binary search over a given array of objects
arrayslicer
Package: arrayslicer
Created by: gabmontes
Last modified: Mon, 13 Jun 2022 03:29:24 GMT
Version: 1.2.3
Downloads: 2,012
Repository: https://github.com/gabmontes/arrayslicer

Install

npm install arrayslicer
yarn add arrayslicer

Array Slicer

Node.JS module that implements an optimized binary search over a given array of objects.

Quick example

 var IndexedArray = require("arrayslicer");

var ia = new IndexedArray([{num: 1}, {num: 2}, {num: 5}], "num");

ia.fetch(2); // ia.cursor is set to 1
ia.get(1); // -> {num: 1}
ia.getRange(2, 5); // -> [{num: 2}, {num: 5}]

Install

 npm install arrayslicer

API

IndexedArray(array, index)

Creates a new IndexedArray object based on array and indexed by the property index.

IndexedArray.sort()

Sort the IndexedArray by its index property. This is needed to ensure the values are retrieved properly.

IndexedArray.fetch(value)

Sets the internal pointer of the IndexedArray, called cursor, to the element with index equal value.

If there are no matching elements, the properties nexthigh and nextlow are set to the nearest indexes to value.

IndexedArray.get(value)

Gets the element with index equal value.

If there are no matching elements, the function will return null.

IndexedArray.get(begin, end)

Returns an array containing all the elements within begin and end, including both values if exact matches are found within the data.

IndexedArray.setCompare(fn)

Use a custom compare function.

IndexedArray.setSort(fn)

Use a custom sort function.

Licence

WTFPL

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin