I need to find a way to fill an Array with a specific amount of nulls and only replace the last value with a specific number.
My idea would to create an empty Array, set Array.length = desiredLength and set Array[lastElement] = value. But how to fill the rest?
Example:
Input: Array should have a length of five and last value should be 123
Output: [null, null, null, null, 123]
Array(5).fill(null, 0, 4).fill(123, 4, 5)