Skip to content

Commit

Permalink
findone
Browse files Browse the repository at this point in the history
  • Loading branch information
nalbam committed Oct 6, 2023
1 parent 0c80d97 commit 18ccfd8
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions public/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ class Timer {
}
}

findone() {
if (this.records.length == 0) {
return;
}

this.sorted = this.records.slice();
this.sorted.sort(compare);
this.bestlap.innerText = this.format(this.sorted[0]);
}

record() {
let li = document.createElement('li');
li.innerText = this.format(this.times);
Expand All @@ -147,10 +157,7 @@ class Timer {
// Save the lap time
this.records.push(this.times);

// Update the best lap time
this.sorted = this.records.slice();
this.sorted.sort(compare);
this.bestlap.innerText = this.format(this.sorted[0]);
this.findone();
}

drop() {
Expand All @@ -164,10 +171,7 @@ class Timer {
this.results.removeChild(this.results.lastChild);
this.records.splice(this.records.length - 1, 1);

// Update the best lap time
this.sorted = this.records.slice();
this.sorted.sort(compare);
this.bestlap.innerText = this.format(this.sorted[0]);
this.findone();
}

reject() {
Expand Down Expand Up @@ -204,10 +208,7 @@ class Timer {
this.results.removeChild(this.results.lastChild);
this.records.splice(this.records.length - 1, 1);

// Update the best lap time
this.sorted = this.records.slice();
this.sorted.sort(compare);
this.bestlap.innerText = this.format(this.sorted[0]);
this.findone();

this.start();
}
Expand Down

0 comments on commit 18ccfd8

Please sign in to comment.