Read here. Code on desktop. The coding workspace opens on screens 1024px and wider.
JavaScript interview question
Array with
easy10 min
Create an array copy with one value replaced at a positive or negative index, leaving the original array unchanged.
Requirements
Implement arrayWith(array, index, value), the actual-array subset of Array.prototype.with. Return a new array of the original length with only the chosen value replaced.
Normalize numeric indices by truncating towards zero; NaN is treated as 0. A negative integer counts backwards from the end.
Throw RangeError for out-of-bounds or infinite indices, including every index on an empty array. Do not extend the array.
Copy other values by reference. Unlike slice, the result is dense: sparse slots become actual properties with value undefined. Do not read the original value at the replaced index.
Do not mutate the input, replace native methods, or use native with. Assume actual arrays and numeric indices; general coercion and array subclasses/species are outside scope. The replacement may have any type, including undefined.