Created
December 6, 2021 23:39
-
-
Save belichuk/6180e21cb48b595868369bd476581b6b 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
const shift = (offset, points) => points.map(pt => { | |
const point = typeof pt == 'object' ? pt : JSON.parse(pt); | |
return {x: point.x + offset.x, y: point.y + offset.y}; | |
}); | |
const polyline = [ | |
{x: 0, y: 0}, | |
{x: 10, y: 10}, | |
'{"x": 20, "y": 20}', | |
{x: 30, y: 30}, | |
]; | |
const shifted = shift({x: 10, y: 10}, polyline); | |
console.log(shifted); | |
console.log(polyline); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
==
shift
to parsing, iteration, and moving functions