Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.prototype.hugoSort = function(arrayWithObjectIds,idPropName){
- var ao = this, a = arrayWithObjectIds, id = idPropName || "id";
- ao.sort(function(x,y){
- return a.indexOf(x[id])>=a.indexOf(y[id]) ? 1 : -1;
- });
- };
- var cats = [
- {id:1, name: "Boris"},
- {id:2, name: "Moxy"},
- {id:3, name: "Billie"}
- ];
- cats.hugoSort([3,1,2]);
- console.log(cats); // Billie, Boris, Moxy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement