Last active
December 27, 2017 07:44
-
-
Save nomanHasan/85c91e531128fdbde36477fe70e3f8bb to your computer and use it in GitHub Desktop.
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
let Size20 = [-30, -10, 10, 30, 50, 70, 90, 110, 130, 150]; | |
let Size30 = [-40, -10, 20, 50, 80, 110, 140, 170, 200]; | |
const assert = (target, source, title=`TEST ${target} === ${source}`) => { | |
if(target === source){ | |
return {title, status: "SUCCESS"} | |
}else{ | |
return {title, status: "FAILED"} | |
} | |
} | |
roundToN = (number, offset= 0, size= 0) => { | |
let multiplier = 1; | |
let next = 0; | |
let prev = 0; | |
while (next < number) { | |
multiplier += 1; | |
next = offset + size * multiplier; | |
} | |
prev = number - size; | |
console.log(`prev ${prev}, next${next}, size${size}, offset${offset}, number${number}`); | |
const diff = number - prev; | |
if (diff >= size / 2 ) { | |
return next; | |
}else { | |
return prev; | |
} | |
} | |
assert(roundToN(57), 50); | |
assert(roundToN(72), 80); | |
assert(roundToN(86), 80); | |
assert(roundToN(105), 110); | |
assert(roundToN(-30), -40); | |
assert(roundToN(-22), -10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment