Created
June 19, 2020 17:37
-
-
Save geomago/e60f27d3c937f915e4fe7c1e895c783a to your computer and use it in GitHub Desktop.
restruct_array
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
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