-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.js
More file actions
30 lines (28 loc) · 1.23 KB
/
sort.js
File metadata and controls
30 lines (28 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
let arr = [
{cartoon:'Sonic the Hedgehog', yearReleased:1993, genres:'adventure'},
{cartoon:'Teen Titans', yearReleased:2003, genres:'thriller'},
{
cartoon: 'Pokemon',
yearReleased: 1996,
genres: 'video game',
},
{cartoon: 'Bojack Horseman', yearReleased: 2014, genres:'comedy'},
{cartoon: "Bob's Burgers", yearReleased: 2011, genres: "adult"},
{cartoon: "Avatar the Last Airbender", yearReleased: 2005, genres:'adventure'},
{cartoon: "Yugioh", yearReleased: 1999, genres: "adventure"},
{cartoon: 'SpongeBob SquarePants', yearReleased: 1989, genres: 'comedy'},
{cartoon: 'Tangled', yearReleased: 2010, genres: 'adventure'},
{cartoon: 'Tom and Jerry', yearReleased: 1940, genres: 'comedy'},
{ cartoon: 'Stewie Griffin', yearReleased: 1999, genres: 'adult'},
{cartoon:'Ben 10', yearReleased:2005,genres:'adventure'},
{
cartoon: `Rick and Morty`, yearReleased: 2013, genres: 'dark'
},
{cartoon:'The Spectacular Spider-Man', yearReleased:2008, genres:'superhero'}
]
//Sorting numbers
arr.sort((a,b)=>a.yearReleased-b.yearReleased);
console.log(arr);
//Sorting strings
arr.sort((a,b)=>a.cartoon.toLowerCase()>b.cartoon.toLowerCase() ? 1 : -1)
console.log(arr);