Last active
April 18, 2017 00:40
-
-
Save erkobridee/453aa054f08e738966196609ba3e09b8 to your computer and use it in GitHub Desktop.
es6 - cool example of use array destruction + advanced object literal to transform data
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
// from an array of arrays of points | |
const points = [ | |
[4,5], | |
[10,1], | |
[0,40] | |
]; | |
// to array of objects x,y points | |
function transformPointsData(points){ | |
return points.map(([ x, y ]) => { | |
return { x, y }; | |
}); | |
} | |
console.log(transformPointsData(points)); | |
/* | |
[ | |
{ x : 4, y : 5 }, | |
{ x : 10, y : 1 }, | |
{ x : 0, y : 40 } | |
] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment