Skip to content

Commit

Permalink
perf: use indexOf instead of findIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
stropitek committed Jun 29, 2017
1 parent 6e091e7 commit a0f64a1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class ConfusionMatrix {
}

for (let i = 0; i < predicted.length; i++) {
const actualIdx = distinctLabels.findIndex(label => label === actual[i]);
const predictedIdx = distinctLabels.findIndex(label => label === predicted[i]);
const actualIdx = distinctLabels.indexOf(actual[i]);
const predictedIdx = distinctLabels.indexOf(predicted[i]);
if (actualIdx >= 0 && predictedIdx >= 0) {
matrix[actualIdx][predictedIdx]++;
}
Expand Down Expand Up @@ -100,8 +100,8 @@ class ConfusionMatrix {
* @return {number} - The element in the confusion matrix
*/
getCount(actual, predicted) {
const actualIndex = this.labels.findIndex(label => label === actual);
const predictedIndex = this.labels.findIndex(label => label === predicted);
const actualIndex = this.labels.indexOf(actual);
const predictedIndex = this.labels.indexOf(predicted);
if (actualIndex < 0 || predictedIndex < 0) {
throw new Error('The provided label does not exist');
}
Expand Down

0 comments on commit a0f64a1

Please sign in to comment.