I am currently working with a factory that looks like this:
app.factory("ModuleFactory", function (api, $http, $q, filterFilter) {
var moduleList = [];
var categoryList = [];
var moduleTypeList = [];
var academyModuleTypeList = [];
var mostUsed = [];
var lastUpdated = null;
return {
/**
* @description This function retrieves the complete module list for the organization of the user.
* @author Marc Rasmussen
* @returns {d.promise}
*/
getList: function () {
var d = $q.defer();
if (moduleList.length == 0) {
$http.get(api.getUrl('module', null))
.success(function (response) {
moduleList = response;
lastUpdated = new Date();
d.resolve(response);
});
}
else {
d.resolve(moduleList);
}
return d.promise;
},
getMostUsed: function () {
var d = $q.defer();
if(moduleList.length <= 0){
this.getList().then(function () {
})
}
}
}
});
Now, the moduleList
includes a collection of objects
, each containing a field called num_used
.
You'll notice I've created a function named getMostUsed
. What this function should do is return the moduleList sorted in descending order based on the num_used
field.
Although I could use array.sort()
, I'm interested in leveraging the power of an Angular function like filterFilter
to achieve this. Can anyone provide guidance on how to accomplish this?