Hi, help please with the task, the code is there, but I incorrectly prescribed something in it. It is necessary that sorting occurs in ascending kernels (cores)

let arr = [ {cpu: 'Intel', info: {cores: 2, cache: 3 }}, {cpu: 'Intel', info: {cores: 4, cache: 4 }}, {cpu: 'amd', info: {cores: 1, cache: 1 }}, {cpu: 'Intel', info: {cores: 3, cache: 2 }}, {cpu: 'amd', info: {cores: 4, cache: 2 }}, ] function sortByCores() { arr.sort(( prev, next ) => prev.cores - next.cores); return arr; } 

  • one
    prev.info.cores . Well, c next similar. - Yaant

2 answers 2

 let arr = [ { cpu: 'Intel', info: {cores: 2,cache: 3 } }, { cpu: 'Intel', info: {cores: 4,cache: 4 } }, { cpu: 'amd', info: {cores: 1, cache: 1 } }, { cpu: 'Intel', info: {cores: 3, cache: 2 } }, { cpu: 'amd', info: {cores: 4, cache: 2 } }, ] function sortByCores() { arr.sort((a, b) => a.info.cores - b.info.cores); return arr; } sortByCores(); console.log(arr); 

    You have an error in working with objects. You have in each object that you get in sort, there are only two fields cpu and info. And in info two more fields cores and cache. Therefore, the sort function should look like this:

    arr.sort(( prev, next ) => prev.info.cores - next.info.cores);