mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 14:29:29 +01:00
make an object sort function in snippets
This commit is contained in:
parent
27bce53e2e
commit
a992e65b6e
@ -26,17 +26,10 @@ var kick = function(dbot) {
|
||||
// who have kicked other people the most.
|
||||
'~kickstats': function(event) {
|
||||
var orderedKickLeague = function(list, topWhat) {
|
||||
var kickArr = [];
|
||||
for(var kickUser in list) {
|
||||
if(list.hasOwnProperty(kickUser)) {
|
||||
kickArr.push([kickUser, list[kickUser]]);
|
||||
}
|
||||
}
|
||||
|
||||
kickArr = kickArr.sort(function(a, b) { return a[1] - b[1]; });
|
||||
var kickArr = Object.prototype.sort(list, function(key, obj) { return obj[key]; });
|
||||
kickArr = kickArr.slice(kickArr.length - 10).reverse();
|
||||
var kickString = "Top " + topWhat + ": ";
|
||||
|
||||
var kickString = "Top " + topWhat + ": ";
|
||||
for(var i=0;i<kickArr.length;i++) {
|
||||
kickString += kickArr[i][0] + " (" + kickArr[i][1] + "), ";
|
||||
}
|
||||
|
@ -57,18 +57,10 @@ var quotes = function(dbot) {
|
||||
|
||||
// Shows a list of the biggest categories
|
||||
'~qstats': function(event) {
|
||||
var qSizes = [];
|
||||
for(var cat in quotes) {
|
||||
if(quotes[cat].length != 0) {
|
||||
qSizes.push([cat, quotes[cat].length]);
|
||||
}
|
||||
}
|
||||
|
||||
qSizes = qSizes.sort(function(a, b) { return a[1] - b[1]; });
|
||||
var qSsizes = Object.prototype.sort(quotes, function(key, obj) { obj[key].length });
|
||||
qSizes = qSizes.slice(qSizes.length - 10).reverse();
|
||||
|
||||
var qString = dbot.t('large_categories');
|
||||
|
||||
for(var i=0;i<qSizes.length;i++) {
|
||||
qString += qSizes[i][0] + " (" + qSizes[i][1] + "), ";
|
||||
}
|
||||
|
12
snippets.js
12
snippets.js
@ -178,7 +178,17 @@ Object.prototype.length = function() {
|
||||
if(this.hasOwnProperty(key))
|
||||
l++;
|
||||
return l;
|
||||
}
|
||||
};
|
||||
|
||||
Object.prototype.sort = function(object, scorer) {
|
||||
var sortArr = [];
|
||||
for(var key in object) {
|
||||
if(object.hasOwnProperty(key)) {
|
||||
sortArr.push([key, scorer(key, object)]);
|
||||
}
|
||||
}
|
||||
return sortArr.sort(function(a, b) { return a[1] - b[1]; });
|
||||
};
|
||||
|
||||
/*** Integer ***/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user