JSPM

operate-array

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q14391F
  • License ISC

Performs operation on arrays

Package Exports

  • operate-array

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (operate-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

oprerate-array

oprerate-array is a package that provides various functions to easily and efficiently operate on arrays.

Installation

$ npm install operate-array --save

Usage

deleteElement(array, element, occurrence)

Deletes the element from the array as per the specified occurrences from the left and returns a new array with remaining elements. If no occurrence is specified it will delete all the occurrences of that element in that array.

var operator = require('operate-array');

var resultArray = operator.deleteElement([1, 2, 3, 4, 4, 5], 4);

console.log(resultArray);
// [1, 2, 3, 5];
var operator = require('operate-array');

var resultArray = operator.deleteElement([1, 2, 3, 4, 4, 5], 4, 1);

console.log(resultArray);
// [1, 2, 3, 4, 5];

trim(array, startIndex, endIndex)

Deletes the elements in the range of the start and end index both inclusive and returns a new array with remaining elements

var operator = require('operate-array');

var resultArray = operator.trim([1, 2, 3, 4, 4, 5], 2, 4);

console.log(resultArray);
// [1, 2, 5];

Run Tests

$ npm install
$ npm run test
  • Test 1 : Delete all occurences of an element.
  • Test 2 : Delete one occurences of an element.
  • Test 3 : Delete all occurences of an element in an empty array.
  • Test 4 : Delete one occurences of an element in an empty array.
  • Test 5 : Delete an element not present in array.
  • Test 6 : Trim/Remove elements the array with specified index.
  • Test 7 : Trim/Remove elements the array with specified index in an empty array.
  • Test 8 : Trim/Remove elements the array with specified index in an empty array.
  • Test 9 : Trim/Remove elements the array with specified index in an empty array.