Created
March 21, 2017 08:26
-
-
Save jsoendermann/294b74ba89940874dc24301c359ec0fa to your computer and use it in GitHub Desktop.
Simple clustering
This file contains 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 characters
const EPSILON = 0.1 | |
const cluster = (array, threshold) => { | |
for (const e of array) { | |
return array.filter(e_ => Math.abs(e - e_) < EPSILON).length / array.length >= threshold | |
} | |
} | |
if ( | |
cluster([0, 0.0001, 0.01, 0.0, 9], 0.5) && | |
cluster([0, 0.0001, 0.01, 0.0, 9], 0.75) && | |
!cluster([0, 0.0001, 0.01, 0.0, 9], 0.9) && | |
!cluster([0, 0, 0, 1, 1, 1, 1], 0.75) && | |
!cluster([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0.2) | |
) { | |
console.log('Success') | |
} else { | |
console.log('Failure') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment