DEV Community

Discussion on: Simplest way to compare two numbers array in JS

Collapse
 
marcosteinke profile image
Marco Steinke

This was the solution for a subtask of a problem I recently solved in a project.

I compared two vectors element-wise and counted the amount of distinct elements

getTotalDifference(anotherVector) {
    let diff = 0;
    this.values.forEach((e,i) => { return (this.values[i] != anotherVector[i]) ? diff++ : diff = diff; })
    return diff;
}
Enter fullscreen mode Exit fullscreen mode