square the elements of a sorted list and give the output in sorted order
If you start at both ends and compare these values, you can step down towards the center, unshifting the values, squaring them and unshifting them to the resulting array.

You don't need to square the values until you add them to the array. You can compare to find the greater value by negating the left side. 

One \$O(n)\$ solution is as follows



function sortSquares(arr) {
    const res = [];
    var start = 0; end = arr.length - 1, idx = end;
    while (start &lt;= end) {
        res[idx--] = (-arr[start] &gt; arr[end] ? arr[start++] : arr[end--]) ** 2;
    }
    return res;
}

// Test code
[
    [-9,-5,-0.5,0.6,1, 2, 3,8],
    [1, 2, 3,8],
    [-10, -8, -3, -1, -1, 1, 1, 1],    
    [0.6,1, 2, 3,8],
    [-9,-6,-3,-2,-1],
    [-9,-6,-3,-2,-1,1,2,3,6,9],
].forEach(a =&gt; log(a, sortSquares(a)));


function log(data, data1) {
   data = "[" + data + "] -=&gt;&gt; [" + data1 + "]";
   info.appendChild(Object.assign(document.createElement("div"),{textContent: data}));
}
&lt;code id="info"&gt;&lt;/code&gt;