项目作者: writetome51

项目描述 :
Replaces adjacent items in the array with same number of new adjacent items
高级语言: TypeScript
项目地址: git://github.com/writetome51/array-replace-adjacent-at.git
创建时间: 2018-11-05T05:00:11Z
项目社区:https://github.com/writetome51/array-replace-adjacent-at

开源协议:MIT License

下载


replaceAdjacentAt\(
startingIndex: number,
newValues: T[],
array: T[]
): void

Replaces adjacent items, beginning at startingIndex, with the same number
of newValues, in array.
index can be negative or positive.

Examples:

  1. let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  2. replaceAdjacentAt(0, [20], arr);
  3. // arr is now [ 20, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
  4. replaceAdjacentAt(0, [30, 31, 32, 33], arr);
  5. // arr is now [ 30, 31, 32, 33, 5, 6, 7, 8, 9, 10 ]
  6. replaceAdjacentAt(-3, [1, 2, 3], arr);
  7. // arr is now [ 30, 31, 32, 33, 5, 6, 7, 1, 2, 3 ]
  8. // This works because the second arg has length greater than zero:
  9. replaceAdjacentAt(-3, 'aaa', arr);
  10. // arr is now [ 30, 31, 32, 33, 5, 6, 7, 'a', 'a', 'a' ]
  11. // This errors because the second arg has length of zero:
  12. replaceAdjacentAt(0, [], arr);
  13. // Error: 'Input must be integer greater than zero'
  14. // This errors because arr only has 2 items left at index 8:
  15. replaceAdjacentAt(8, ['a', 'b', 'c'], arr);
  16. // Error: 'the array does not have enough items to fulfill your request'

Installation

npm i @writetome51/array-replace-adjacent-at

Loading

  1. import { replaceAdjacentAt } from '@writetome51/array-replace-adjacent-at';