Joined July 2018
·

pczegle

N/A at N/A
·
New York
·
·
·

Posted to JavaScript Sort by Two Fields over 1 year ago

Thanks for sharing this great stuff!

It got me thinking about sorting by even more keys. I came up with the following, which seems to work, for Microsoft Virtual Academy's car lot example with car year, car make, and car model in Lesson 15 on Object Literals at:

https://mva.microsoft.com/en-US/training-courses/javascript-fundamentals-for-absolute-beginners-14194?l=rUtOmHVxE_6200115881

I'm a JavaScript newbie, but as far as I can tell, it can be scaled up to as many keys as necessary:

carLot.sort(function(a,b){
return a.year>b.year?true:(a.make>b.make?true:(a.model>b.model?true:false));
});

Achievements
1 Karma
0 Total ProTip Views
Interests & Skills