Skip to content

Instantly share code, notes, and snippets.

@wowotek
Created August 7, 2020 14:28
Show Gist options
  • Save wowotek/27dd79b285cf5daa55d2f9b570199219 to your computer and use it in GitHub Desktop.
Save wowotek/27dd79b285cf5daa55d2f9b570199219 to your computer and use it in GitHub Desktop.
let len = messages.length;
for (let i = 0; i < len; i++) {
let min = i;
for (let j = i + 1; j < len; j++) {
if (messages[j].timestamp > messages[min].timestamp) {
min = j;
}
}
if (min !== i) {
let tmp = messages[i];
messages[i] = messages[min];
messages[min] = tmp;
}
}
return messages;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment