Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #25 from chrismelman/org

added funtion to check if array has element with a property with a value
  • Loading branch information...
commit aac976b70d0e2c498964ef66d51cacba150a0975 2 parents a2b47bf + d24653e
chrismelman chrismelman authored
Showing with 6 additions and 1 deletion.
  1. +6 −1 mobl.mobl
7 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;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.