Sorting algorithm
I have two objects, Artists and Songs. Artists={ A0: [ "a0", "a1", ...], A1: [ "a21", "a69", ...], ... //255 artists } Songs={ s0:{ ... album: "a0", ... }, s1:{ ... album: "a182", ... }, ... //26,500 songs } I need to find ten artists with most songs. I used this naive approach: let artists=Object.keys(Artists) .map(m=>[ m, Artists[m].map(n=> Object.keys(Songs) .filter(f=>Songs[f].album==n).length) .reduce((mm,n)=>mm+n) ]) .sort((m,n)=>n[1]-m[1]) .slice(0,10); But it takes 70 seconds to execute. Could you come up with a much faster approach? There are 805 albums. Artists object is here http://remi.rf.gd/JS/artists.js Songs object is here http://remi.rf.gd/JS/songs.js https://code.sololearn.com/WK4UfhwmJhrB/?ref=app