Is there a function to insert an element at i-th position in a list?

You can, because Array.slice and Array.append are log time not linear. Of course, you will only see a difference for large enough arrays.

Check out this example of a gap buffer capable of working smoothly with 1M lines of text, implemented using arrays and making use of Array.slice and Array.append to quickly insert or refocus the ‘gap’:

https://kind-colden-ebafc2.netlify.app/

3 Likes