EDIT:
Per your requirements, I came up with this:
$scope.compFunc = function(actual, expected) {
var expectedSplit = expected.split(' ');
var fullActual;
//Search people for the person the name belongs to
$scope.names.forEach(function(person){
angular.forEach(person, function(name){
if (name === actual) {
fullActual = person;
}
})
})
//create an array from the names object for comparison
var fullActualArray = [];
angular.forEach(fullActual, function(name, key){
if (key != '$$hashKey')
fullActualArray.push(name = name.toLowerCase());
})
fullActualArray.sort();
expectedSplit.sort();
return actual.toLowerCase().indexOf(expected.toLowerCase()) > -1||
fullActualArray.join(',') === expectedSplit.join(',');
};
This should work just how you expect.
FIDDLE
Note: I used forEach for the sake of clarity, but if you have large amounts of data you may want to change it to for loops, which are 90% faster and can break when a match is found.
Previous solutions:
It's very simple, checks if either the value entered in the search (expected) exists in either firstname or lastname (actual), or the opposite. So entering "Robert Downy" should work, but so will "Robert blargh" or "abcDownyefg". Checking against the whole thing (firstname + lastname) is something that you have to do outside the comparison function, and is not supported out of the box with angular as far as I know.
I've also used the following to create a new array for comparison using the full names:
$scope.fullnames = $scope.names.map(function(name){
return {
firstname: name.firstname,
lastname: name.lastname,
fullname :name.firstname + " " + name.lastname
}
})
While extending the original array can be done like this:
$scope.names.forEach(function(name){
angular.extend(name,{fullname:name.firstname + " " + name.lastname});
})
This is simple and effective, and is what I would do.
fullnameto each object - Mosho