runtime
- Visual Studio Code v1.15.1 native compiler
- Node.js v8.2.1
- OS: Windows 10
Description
I want to add "After sorting:" between the original arry and sort arry, they look like this:

But the console sometimes shows:

Why did the for-of-loop not finish, jump to start console.log? Source:
function getRandom() {
return Math.round(Math.random() * 100);
}
var score = [
["a", getRandom()],
["b", getRandom()],
["c", getRandom()],
["d", getRandom()],
["e", getRandom()]
];
console.log("Before sort:");
for (let m of score) {
console.log(m);
}
score.sort((a, b) => {
return b[1] - a[1];
});
console.log("After sort:");
for (let n of score) {
console.log(n);
}
source
share