Skip to content

Instantly share code, notes, and snippets.

@jsoendermann
Created March 21, 2017 08:26
Show Gist options
  • Save jsoendermann/294b74ba89940874dc24301c359ec0fa to your computer and use it in GitHub Desktop.
Save jsoendermann/294b74ba89940874dc24301c359ec0fa to your computer and use it in GitHub Desktop.
Simple clustering
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