@writetome51/array-remove-adjacent-to-value
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

removeAdjacentToValue(
      {
           value: anyExceptObject,
           offset: integer,
           howMany: integer_greater_than_zero
      },
      array
): void

Removes howMany adjacent items from array, starting with, or
close to, value. Exactly where removal begins is decided by offset,
which is the position, relative to value, where to begin removing.
For example, if offset is 0, then removal begins at value. If -1,
it begins one place to the left of value. If 1, it begins one place to the
right.

Note: the function only works with the first found instance of value.

Examples

let array = [1,3,5,7,9,11,13,15,17];  
removeAdjacentToValue(
    {value: 11, offset: 0, howMany: 3},  
    array
);  
// items that get removed are [11,13,15] .  
// array is now [1,3,5,7,9,17].  


let array = [1,3,5,7,9,11,13,15,17];  
removeAdjacentToValue(
    {value: 11, offset: -2, howMany: 4}, 
    array
);  
// items that get removed are [7,9,11,13] .  
// array is now [1,3,5,15,17] .


let array = [1,3,5,7,9,11,13,15,17];  
removeAdjacentToValue(
    {value: 11, offset: 2, howMany: 2}, 
    array
);  
// items that get removed are [15,17] .  
// array is now [1,3,5,7,9,11,13] .

Installation

npm i @writetome51/array-remove-adjacent-to-value

Loading

// if using TypeScript:
import {removeAdjacentToValue} from '@writetome51/array-remove-adjacent-to-value';
// if using ES5 JavaScript:
var removeAdjacentToValue = 
    require('@writetome51/array-remove-adjacent-to-value').removeAdjacentToValue;

Package Sidebar

Install

npm i @writetome51/array-remove-adjacent-to-value

Weekly Downloads

5

Version

1.0.3

License

MIT

Unpacked Size

6.54 kB

Total Files

7

Last publish

Collaborators

  • writetome51