July 19th, 2024
What's missing in this code?
const arr = [[5], 3, [1], 4, [2]];
// sort with bubble sort
for (let i = 0; i < arr.length; i++)
for (let j = 0; j < arr.length - i - 1; j++)
let jNum =
(arr[j]) ? arr[j][0] : arr[j];
let j1Num =
(arr[j + 1])
? arr[j + 1][0]
: arr[j + 1];
if (jNum > j1Num)
[
,
] = [arr[j + 1], arr[j]];
}
}
}
Type or select from these options