Skip to content

Instantly share code, notes, and snippets.

@perfectmak
Last active January 26, 2018 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perfectmak/fcda59451205919ef9f0429924d9a84a to your computer and use it in GitHub Desktop.
Save perfectmak/fcda59451205919ef9f0429924d9a84a to your computer and use it in GitHub Desktop.
function quantize(k, colors) {
...
const centerDistances = new Array(k)
for(let i = 0; i < colors.length; i++) {
for(let j = 0; j < centers.length; j++) {
centerDistances[j] = distance(centers[j], colors[i])
}
const minimumDistance = Math.min(...centerDistances)
const closestCentersIndex = centerDistances.indexOf(minimumDistance)
colors[i] = centers[closestCentersIndex]
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment