I am developing a game that performs a function in JavaScript that counts how long the player took to finish until reaching the last phase:
function formatatempo(segs) {
var min = 0;
va hr = 0;
while (segs >= 60) {
if (segs >= 60) {
segs = segs - 60;
min = min + 1;
}
}
while (min >= 60) {
if (min >= 60) {
min = min - 60;
hr = hr + 1;
}
}
if (hr < 10) {
hr = "0" + hr
}
if (min < 10) {
min = "0" + min
}
if (segs < 10) {
segs = "0" + segs
}
fin = hr + ":" + min + ":" + segs
return fin;
}
In the above case, at the end of execution the variable fin
is returned with the time covered. The problem is that I need to store these outputs in a ranking, how could I sort them out from the smallest to the longest?