Skip to content

Instantly share code, notes, and snippets.

@geomago
Created June 19, 2020 17:37
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 geomago/e60f27d3c937f915e4fe7c1e895c783a to your computer and use it in GitHub Desktop.
Save geomago/e60f27d3c937f915e4fe7c1e895c783a to your computer and use it in GitHub Desktop.
restruct_array
let newCars = cars2.slice(0).sort( (a,b) => a.price - b.price )
.map( (item,index) => {
item.position = index+1;
delete item.colour;
return item;
}
);
// RESULT IS
[
{id:5,make:"McLaren",model:"New GT",price:203000,position:1},
{id:9,make:"Lamborghini",model:"Huracan",price:206790,position:2},
{id:2,make:"Ferrari",model:"F8 Spider",price:262000,position:3},
{id:6,make:"Ferrari",model:"F8 Spider",price:262000,position:4},
{id:10,make:"Bugatti",model:"Chiron Sport 110 ans",price:16000000,position:5}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment