made with esnextbin
Last active
October 10, 2016 03:53
-
-
Save trxcllnt/4fc7f87f3f141ea225492ea760f00a34 to your computer and use it in GitHub Desktop.
esnextbin sketch
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
</body> | |
</html> |
This file contains hidden or 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 bounds = 500; | |
const inputs = [-1005, -760, -750, -515, -500, -260, -250, 0, 250, 260, 500, 515, 750, 760, 1005]; | |
const output = [ -5, 240, 250, 15, 0, -240, -250, 0, 250, 240, 0, -15, -250, -240, 5]; | |
let runs = -1; | |
function adjust(value, bounds) { | |
if (isNaN(value = Number(value))) { | |
throw new Error('NaN value'); | |
} | |
const sep = Math.round(value / bounds); | |
const pos = sep % 2 === 0 ? 1 : -1; | |
return (value - (bounds * sep)) * pos; | |
} | |
console.clear(); | |
inputs.forEach((value, index) => { | |
runs = -1; | |
const actual = adjust(value, bounds); | |
const expected = output[index]; | |
if (actual !== expected) { | |
throw new Error(`${value}: expected ${actual} to equal ${expected}`); | |
} else { | |
console.log(`${value}: success`); | |
} | |
}); |
This file contains hidden or 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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"babel-runtime": "6.11.6" | |
} | |
} |
This file contains hidden or 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
'use strict'; | |
var bounds = 500; | |
var inputs = [-1005, -760, -750, -515, -500, -260, -250, 0, 250, 260, 500, 515, 750, 760, 1005]; | |
var output = [-5, 240, 250, 15, 0, -240, -250, 0, 250, 240, 0, -15, -250, -240, 5]; | |
var runs = -1; | |
function adjust(value, bounds) { | |
if (isNaN(value = Number(value))) { | |
throw new Error('NaN value'); | |
} | |
var sep = Math.round(value / bounds); | |
var pos = sep % 2 === 0 ? 1 : -1; | |
return (value - bounds * sep) * pos; | |
} | |
console.clear(); | |
inputs.forEach(function (value, index) { | |
runs = -1; | |
var actual = adjust(value, bounds); | |
var expected = output[index]; | |
if (actual !== expected) { | |
throw new Error(value + ': expected ' + actual + ' to equal ' + expected); | |
} else { | |
console.log(value + ': success'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment