You could try writing a translation of the kata raulbc777 mentioned, there is small difference tho, the array size is fixed in the other kata.
There are some other problems with yours
No random tests (this is an issue)
Your solution mutates the input, so when evaluating the user's answer, if you use the same array, if you create the expected value first, you'll be giving the user a sorted array. There are two ways of solving that problem, change your solution so it doesn't mutate the input and calculate the expected result before the array is passed to the users' function, or pass the user's function a shallow copy and calculate the expected value after that. Mutating the input is a bad practice.
Tests should not print anything on success.
The tests should only compare values returned by
top
, and do everything explicitly, instead of relying on some hidden function.Node 12 should be enabled, and class syntax should be used.
These input/output has nothing to do with the task.
The tests are easily cheatable.
The same problem on LeetCode. Did you get permission to reproduce it here?
No random tests.
You could try writing a translation of the kata raulbc777 mentioned, there is small difference tho, the array size is fixed in the other kata.
There are some other problems with yours
It's a duplicate : https://www.codewars.com/kata/57f5e7bd60d0a0cfd900032d