@writetome51/array-replace-between
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

replaceBetween(
      numItemsToPreserveAtEachEnd,
      newValues,
      array
): void

Replaces everything between numItemsToPreserveAtEachEnd with newValues in array.

Examples

let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
replaceBetween(3, [100], arr);
// arr is now [ 1, 2, 3, 100, 8, 9, 10]

arr = [1, 2, 3, 4, 5];
replaceBetween(1, [20, 30], arr);
// arr is now [1, 20, 30, 5]

// You can replace something with nothing. Example:

arr = [ 1, 2, 3, 4, 5, 6 ];
replaceBetween(2, [], arr);
// arr is now [ 1, 2, 5, 6 ]

Installation

npm i @writetome51/array-replace-between

Loading

// if using TypeScript:
import {replaceBetween} from '@writetome51/array-replace-between';
// if using ES5 JavaScript:
var replaceBetween = 
    require('@writetome51/array-replace-between').replaceBetween;

Package Sidebar

Install

npm i @writetome51/array-replace-between

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

10.7 kB

Total Files

7

Last publish

Collaborators

  • writetome51