made with esnextbin
Last active
October 10, 2016 02:17
-
-
Save trxcllnt/fe831565e8be23d3825463e938b79265 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 = [-750, -515, -500, -260, -250, 0, 250, 260, 500, 515, 750]; | |
const output = [ 250, 15, 0, -240, -250, 0, 250, 240, 0, -15, -250] | |
// const output = [-3, 0, 3, 0, 3, 0, -3, 0, 3, 0, -3]; | |
// const inputs = [15, 12, 9, 6, 3, 0, -3, -6, -9, 12, -15]; | |
function adjust(value, bounds) { | |
const mod = value % bounds; | |
const pos = Math.round(Math.abs(value) / bounds) % 2 === 0 ? 1 : -1; | |
return ( | |
Math.abs(value) <= bounds / 2 ? (value % bounds) : | |
Math.abs(value) < bounds ? (bounds % value) * Math.sign(value) : | |
Math.abs(value % bounds) * Math.sign(value) * pos); | |
} | |
inputs.forEach((value, index) => { | |
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 _sign = require("babel-runtime/core-js/math/sign"); | |
var _sign2 = _interopRequireDefault(_sign); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var bounds = 500; | |
var inputs = [-750, -515, -500, -260, -250, 0, 250, 260, 500, 515, 750]; | |
var output = [250, 15, 0, -240, -250, 0, 250, 240, 0, -15, -250]; | |
// const output = [-3, 0, 3, 0, 3, 0, -3, 0, 3, 0, -3]; | |
// const inputs = [15, 12, 9, 6, 3, 0, -3, -6, -9, 12, -15]; | |
function adjust(value, bounds) { | |
var mod = value % bounds; | |
var pos = Math.round(Math.abs(value) / bounds) % 2 === 0 ? 1 : -1; | |
return Math.abs(value) <= bounds / 2 ? value % bounds : Math.abs(value) < bounds ? bounds % value * (0, _sign2.default)(value) : Math.abs(value % bounds) * (0, _sign2.default)(value) * pos; | |
} | |
inputs.forEach(function (value, index) { | |
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