There is only a one line difference and was wondering if it was at all possible!
function sortHot() {
var order = [];
$("#container").children(".submission-preview").each(
function() {
var key = $(this).attr('id');
var value = $("div#" + key.replace("sub", "votes")).html() * key.replace("sub", "");
order.push([key, value]);
}
);
return order;
}
function sortNew() {
var order = [];
$("#container").children(".submission-preview").each(
function() {
var key = $(this).attr('id');
var value = key.replace("sub", "");
order.push([key, value]);
}
);
return order;
}
function sortTop() {
var order = [];
$("#container").children(".submission-preview").each(
function() {
var key = $(this).attr('id');
var value = $("div#" + key.replace("sub", "votes")).html();
order.push([key, value]);
}
);
return order;
}
You could use a
switchwith an argument passed to the function:Then call it like this, for the three respective options: