đ§ Exercices JS
Evaluer surprise !
const action = function (tab) {
let i = 0
, j = tab.length - 1;
while (i < j) {
if (tab[i] <= 0) {
i++
}
else {
let tmp = tab[i];
tab[i] = tab[j];
tab[j] = tmp;
// [tab[j], tab[i]] = [tab[i], tab[j]]
j--
}
}
return tab
}
const surprise = action([-1, 1, -2, 10, 3])
console.table(surprise)