You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2006/07/05 20:30:42 UTC
svn commit: r419333 - /incubator/xap/trunk/src/xap/util/Utils.js
Author: mturyn
Date: Wed Jul 5 13:30:42 2006
New Revision: 419333
URL: http://svn.apache.org/viewvc?rev=419333&view=rev
Log:
Added indexOf() and contains() methods on Arrays.
Modified:
incubator/xap/trunk/src/xap/util/Utils.js
Modified: incubator/xap/trunk/src/xap/util/Utils.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/Utils.js?rev=419333&r1=419332&r2=419333&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/util/Utils.js (original)
+++ incubator/xap/trunk/src/xap/util/Utils.js Wed Jul 5 13:30:42 2006
@@ -53,3 +53,33 @@
prompt("",s.replace(/[\r\n]/g,"^")) ;
}
+
+
+/**
+ * Does an array contain an element?
+ * @param anArray an array
+ * @param elem
+ * @return true/false if the array does/n't contain at least one el: el == elem
+**/
+Utils.doesArrayContain = function(anArray, anObject){
+ return (Utils.indexOfFirst(anArray, anObject)>-1) ;
+}
+
+/**
+ * At what index can you find a given element?
+ * @param anArray an array
+ * @param elem
+ * @return index>=0 if the array contains at least one el: el == elem, -1 otherwise:
+**/
+
+Utils.indexOfFirst = function(anArray, anObject){
+ var result=-1 ;
+ for (var i=0; i<anArray.length; ++i){
+ if (anArray[i]==anObject){
+ result = i ;
+ break ;
+ }
+ }
+ return result ;
+}
+