Permalink
Browse files

added funtion to check if array has element with a property with a value

plus refactored containsEntity to use this function
  • Loading branch information...
1 parent 0571fe3 commit d24653e26ba41e1444593190d8dad151c2fff5f2 @chrismelman chrismelman committed May 24, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 mobl.mobl
View
@@ -97,6 +97,7 @@ external type Array<T> {
sync function reduce(fn : Function2<T, T, ?>) : ?
sync function contains(el : T) : Bool
sync function containsEntity(el : T) : Bool
+ sync function containsElementWithValue(property : String, value : ?) : Bool
sync function splice(idx : Num, numToDelete : Num) : Array<T>
sync function insert(idx : Num, item : T) : void
sync function remove(item : T) : void
@@ -771,8 +772,12 @@ Array.prototype.contains = function(el) {
};
Array.prototype.containsEnity = function(el) {
+ return this.containsElementWithValue("id", el.id);
+};
+
+Array.prototype.containsElementWithValue = function(prop, val) {
for(var i = 0; i < this.length; i++) {
- if(this[i].id === el.id) {
+ if(this[i][prop] === val) {
return true;
}
}

0 comments on commit d24653e

Please sign in to comment.