Fill an array range in place with negative index support
Implement fillRange(array, value, start, end). It overwrites the elements of array from index start (inclusive) up to index end (exclusive) with value, and returns the same array.
fillRange(array, value, start?, end?) // => array (the same reference)
start defaults to 0 and end defaults to array.length. Passing undefined explicitly also uses the default.1.9 becomes 1 and -1.5 becomes -1.-1 is the last element, so it becomes array.length - 1.0 to array.length. The array never grows or shrinks.start is not less than end after these steps, the array is left unchanged.value itself. Objects are not copied.fillRange([3, 1, 4, 1, 5], 0);
// => [0, 0, 0, 0, 0]
fillRange(['mon', 'tue', 'wed', 'thu', 'fri'], 'off', 1, 3);
// => ['mon', 'off', 'off', 'thu', 'fri']
fillRange([10, 20, 30, 40, 50], -1, -3, -1);
// => [10, 20, -1, -1, 50]
fillRange(['a', 'b', 'c'], 'z', 1, 99);
// => ['a', 'z', 'z'] (end is clamped, length stays 3)
fillRange([1, 2, 3], 0, 2, 1);
// => [1, 2, 3] (start is not less than end)
Do not use Array.prototype.fill or Array.prototype.copyWithin.