|
|
|
|
|
by Klathmon
2958 days ago
|
|
Now there's a thought! What if we used a storage method that didn't grow? In JavaScript we have typed arrays, we could use a `Uint16Array` to store UTF-16 code points as integers in each element, then we could define the amount of eels that our "hovercraft" could store ahead of time in a way that it won't expand. const hovercraftEelCapacity = 331 // We can define our hovercraft to have room for 331 eels
const eel = 'eel'
const hovercraft = new Uint16Array(new ArrayBuffer(2 * eel.length * hovercraftEelCapacity)) // Each "eel" takes up 3 16-bit integers
for (let i = 0; i < hovercraftEelCapacity * eel.length; i += eel.length) {
hovercraft[i] = eel.codePointAt(0)
hovercraft[i+1] = eel.codePointAt(1)
hovercraft[i+2] = eel.codePointAt(2)
}
console.log('Your hovercraft full of eels: ', hovercraft)
|
|