Created
November 15, 2020 19:06
-
-
Save tedshd/2eaaa40cec7102b29d7db8ffba509fea to your computer and use it in GitHub Desktop.
topnine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = { | |
'123': { | |
'count': 123, | |
'type': 'video', | |
'source': '' | |
}, | |
'345': { | |
'count': 345, | |
'type': 'video', | |
'source': '' | |
}, | |
'99': { | |
'count': 99, | |
'type': 'image', | |
'source': '' | |
}, | |
'1': { | |
'count': 1, | |
'type': 'video', | |
'source': '' | |
}, | |
'9786': { | |
'count': 9786, | |
'type': 'image', | |
'source': '' | |
}, | |
'347': { | |
'count': 347, | |
'type': 'video', | |
'source': '' | |
}, | |
}; | |
// Object.keys(data); | |
function topNine (data) { | |
var arr = []; | |
tmp = Object.keys(data).reverse(), | |
l = (tmp.length >= 9) ? 9 : tmp.length; | |
for (let i = 0; i < l; i++) { | |
arr.push(data[tmp[i]]); | |
} | |
return arr; | |
} | |
console.log(topNine(data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment