JavaScript Sort Stack Coding Challenge
You have access to the stack array directly so you can copy the unsorted stack it to a new stack and sort it in place using Array.sort

"use strict";
function sortStack(stack) {
    const sorted = new Stack();
    while (!stack.isEmpty()) { sorted.push(stack.pop()) }
    sorted.storage.sort((a, b) =&gt; a - b);
    return sorted;
}


or

"use strict";
function sortStack(stack) {
    const sorted = new Stack();
    sorted.storage = [...stack.storage].sort((a, b) =&gt; a - b);
    return sorted;
}


If they did not want you to access the storage array directly they would have protected it in closure. (well if that crossed their minds)

BTW your should always add "use strict" to the top of your javascript code as you have neglected to declare any of your variables, making them all global and setting your self up for some horror bugs.

The use strict directive will not let you use undeclared variable.