Last active
August 29, 2015 14:18
-
-
Save jamescostian/217aa6fd9487fc96834b to your computer and use it in GitHub Desktop.
Revisions
-
jamescostian revised this gist
Apr 4, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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|. // So it returns a percentage (so the value is between 0 and 1) const discrepancy = (x, y) => { if (y === 0 && x === 0) { -
jamescostian created this gist
Apr 4, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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) } }