Created
June 1, 2019 13:10
-
-
Save Semigradsky/19923d9158c87fb23dd1346f5c555256 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
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