Array.prototype.fill = function(value, start = 0, end = this.length) {
// Handle negative values for start
if (start < 0) {
start += this.length;
if (start < 0) start = 0;
}
// Handle negative values for end
if (end < 0) {
end += this.length;
}
// Ensure start is not greater than end
if (start > end) {
[start, end] = [end, start];
}
// Fill the array
for (let i = start; i < end; i++) {
this[i] = value;
}
return this;
};