Skip to content

Instantly share code, notes, and snippets.

@Semigradsky
Created June 1, 2019 13:10
Show Gist options
  • Save Semigradsky/19923d9158c87fb23dd1346f5c555256 to your computer and use it in GitHub Desktop.
Save Semigradsky/19923d9158c87fb23dd1346f5c555256 to your computer and use it in GitHub Desktop.
module.exports = function (diffs) {
let diffsX = diffs.reduce((acc, [x, y]) => acc + x, 0);
let diffsY = diffs.reduce((acc, [x, y]) => acc + y, 0);
if ((diffsX % 2) || (diffsY % 2)) {
return null;
}
diffsX = diffsX / 2;
diffsY = diffsY / 2;
return diffs.map(([x, y], pos) => {
if (x === 1 && diffsX) {
diffsX--;
x = -1;
}
if (y === 1 && diffsY) {
diffsY--;
y = -1;
}
return [x, y];
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment