Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / src / tvcm / iteration_helpers.js
index 27535d4..cdd86b3 100644 (file)
@@ -109,6 +109,26 @@ tvcm.exportTo('tvcm', function() {
     }
   }
 
+  function identity(d) {
+    return d;
+  }
+
+  function findFirstIndexInArray(ary, opt_func, opt_this) {
+    var func = opt_func || identity;
+    for (var i = 0; i < ary.length; i++) {
+      if (func.call(opt_this, ary[i], i))
+        return i;
+    }
+    return -1;
+  }
+
+  function findFirstInArray(ary, opt_func, opt_this) {
+    var i = findFirstIndexInArray(ary, opt_func, opt_func);
+    if (i === -1)
+      return undefined;
+    return ary[i];
+  }
+
   return {
     asArray: asArray,
     concatenateArrays: concatenateArrays,
@@ -119,6 +139,8 @@ tvcm.exportTo('tvcm', function() {
     dictionaryKeys: dictionaryKeys,
     dictionaryValues: dictionaryValues,
     iterItems: iterItems,
-    iterObjectFieldsRecursively: iterObjectFieldsRecursively
+    iterObjectFieldsRecursively: iterObjectFieldsRecursively,
+    findFirstIndexInArray: findFirstIndexInArray,
+    findFirstInArray: findFirstInArray
   };
 });