MCPcopy Create free account
hub / github.com/TodePond/ScreenPond / getClosest

Function getClosest

libraries/habitat-embed.js:222–234  ·  view source on GitHub ↗
(number, array)

Source from the content-addressed store, hash-verified

220 };
221
222 const getClosest = (number, array) => {
223 let highscore = Infinity;
224 let winner = 0;
225 for (let i = 0; i < array.length; i++) {
226 const value = array[i];
227 const difference = Math.abs(number - value);
228 if (difference < highscore) {
229 highscore = difference;
230 winner = i;
231 }
232 }
233 return winner;
234 };
235
236 //https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB
237 const getHSL = (red, green, blue) => {

Callers 1

getSplashFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected