Skip to content

Instantly share code, notes, and snippets.

@jamescostian
Last active August 29, 2015 14:18
Show Gist options
  • Save jamescostian/217aa6fd9487fc96834b to your computer and use it in GitHub Desktop.
Save jamescostian/217aa6fd9487fc96834b to your computer and use it in GitHub Desktop.

Revisions

  1. jamescostian revised this gist Apr 4, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion discrepancy.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // Sort of like the difference between x and y, except it's relative to x + y.
    // Sort of like the difference between x and y, except it's relative to |x+y|.
    // So it returns a percentage (so the value is between 0 and 1)
    const discrepancy = (x, y) => {
    if (y === 0 && x === 0) {
  2. jamescostian created this gist Apr 4, 2015.
    15 changes: 15 additions & 0 deletions discrepancy.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // Sort of like the difference between x and y, except it's relative to x + y.
    // So it returns a percentage (so the value is between 0 and 1)
    const discrepancy = (x, y) => {
    if (y === 0 && x === 0) {
    return 0
    }
    else if (x + y === 0) {
    // They're on opposite ends of 0, so they have the largest discrepancy possible
    return 1
    }
    else {
    let difference = Math.abs(x - y)
    return difference / Math.abs(x + y)
    }
    }