http://codepen.io/leongaban/pen/GZgrMK?editors=0010
I'm trying to find the most efficient way to accomplish this, in my actual app, I may have over 1000 items in the bigArray and a few hundred items or even all 1000 items again in the small array.
I need to find all those items and remove them. Lodash is faster than native javascript APIs so that's what I'm trying here:
var myApp = angular.module('myApp',[]);
myApp.controller('MyController', ['$scope', function($scope) {
$scope.greeting = 'The array below should be smaller than bigArray';
$scope.bigArray = [
{ name: 'Leon'},
{ name: 'Eric'},
{ name: 'Wes'},
{ name: 'Gannon'},
{ name: 'Jordan'},
{ name: 'Chris'},
{ name: 'Paulo'},
{ name: 'Gumbo'},
{ name: 'Gilgamesh'}
];
$scope.smallArray = [
{ name: 'Gannon'},
{ name: 'Gumbo'},
{ name: 'Gilgamesh'}
]
$scope.newArray = [];
$scope.removeItems = function() {
_.remove($scope.bigArray, function($scope.smallArray, n) {
return $scope.smallArray[n].name;
});
// $scope.newArray = _.remove($scope.bigArray, function(n) {
// return n.name = _.find($scope.smallArray, 'name');
// });
// _.each($scope.bigArray, function(value, i) {
// _.find($scope.smallArray, 'name');
// });
}
}]);
What I've tried so far without luck.
Why am I asking about a lodash solution? Because the lodash API is faster in a lot of ways than the native Javascript API.
Proof lodash beats native Javascript, these results are from the jspref link Mr.zerkms posted: http://jsperf.com/zerkms-forloop-vs-each-from-lodash