Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

1 participant

@chrismelman
Owner

plus refactored containsEntity to use this function

@chrismelman chrismelman merged commit aac976b into mobl:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 24, 2012
  1. @chrismelman

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

    chrismelman authored
    plus refactored containsEntity to use this function
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 1 deletion.
  1. +6 −1 mobl.mobl
View
7 mobl.mobl
@@ -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;
}
}
Something went wrong with that request. Please try again.