Skip to content

Instantly share code, notes, and snippets.

@prewk
Created February 5, 2015 10:50
Show Gist options
  • Save prewk/fb97fec7d9b9842b920c to your computer and use it in GitHub Desktop.
Save prewk/fb97fec7d9b9842b920c to your computer and use it in GitHub Desktop.
var menuItems = Immutable.List.of(
{ parent_id: 0, id: 1 },
{ parent_id: 1, id: 2 },
{ parent_id: 1, id: 2 }
);
var results1 = menuItems
.filter(function(menuItem) { return menuItem.parent_id === 1; }) // Filter out items with parent_id = 1
.sort(function(childA, childB) { return childA.sort_order - childB.sort_order; }); // Sort them by sort_order
var results2 = menuItems.withMutations(function(list) {
list
.filter(function(menuItem) { return menuItem.parent_id === 1; }) // Filter out items with parent_id = 1
.sort(function(childA, childB) { return childA.sort_order - childB.sort_order; }); // Sort them by sort_order
});
console.log(results1.size); // 2
console.log(results2.size); // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment