The functional version is written in a style that uses tail recursion, which is not optimized in JS. It’s linear if arrays are not copied, which should be the case with TCO.
Both versions are quadratic if arrays are actual arrays and require a single chunk of memory. (push may need to copy the entire array)
Both versions are quadratic if arrays are actual arrays and require a single chunk of memory. (push may need to copy the entire array)