Skip to content

Instantly share code, notes, and snippets.

@erkobridee
Last active April 18, 2017 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erkobridee/453aa054f08e738966196609ba3e09b8 to your computer and use it in GitHub Desktop.
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
// 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