Can you help me figure out why the function to order the "s" array from minor to major is adding the number at the end instead of the beginning? The if statement seems to be true (2 < 7 = true) but the logic is not working as expected. Any advice on how to fix this?
const s = [5, 7, 2];
function editInPlace() {
var newS = []
for (let i = 0; i < s.length; i++) {
if (console.log(s[i] < newS[i - 1])) {
newsS.unshift(s[i])
console.log("Why is it adding at the end even though condition is true: " + newS.splice(s[i]));
} else {
newS.push(s[i]);
console.log("newS value is: " + newS)
}
}
}
editInPlace();