Modified line which contains const players to use arrow function and return it without explicitly writing return statement. — You may ignore this change.
Removed unnecessary Promise.all as the data is already received and we are applying filter and sort functions which are synchronous operations. async is also not required inside the filter callback as we are not performing any asynchronous operations inside filter function.
The main issue is we have to return player.search_rank !== null which is present inside filter function or write it as arrow function without brackets {}.
2
Answers
I’ve modified the above code assuming that
fetchData
function will get the data from API. Please ignore the implementation of fetchData.Changes made:
const players
to use arrow function and return it without explicitly writing return statement. — You may ignore this change.Promise.all
as the data is already received and we are applying filter and sort functions which are synchronous operations.async
is also not required inside thefilter
callback as we are not performing any asynchronous operations insidefilter
function.The main issue is we have to return
player.search_rank !== null
which is present inside filter function or write it as arrow function without brackets{}
.Friend, I did some major changes to your function and now it works just fine.
By the way, it’s possible to make it a one-liner: