www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 6c89acbe0de8d48521b19083c0e97849753b8ffc
parent 6b002f7566c97e4a2c8da2bde09ec3f87a0413c9
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 20 Jun 2006 17:32:40 +0000

Scholar.inArray(needle, haystack) and Scholar.arraySearch(needle, haystack) -- versions of the PHP functions for JS


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/scholar.js | 30++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/scholar.js b/chrome/chromeFiles/content/scholar/xpcom/scholar.js @@ -23,6 +23,8 @@ var Scholar = new function(){ this.getString = getString; this.flattenArguments = flattenArguments; this.join = join; + this.inArray = inArray; + this.arraySearch = arraySearch; this.randomString = randomString; this.getRandomID = getRandomID; @@ -198,6 +200,34 @@ var Scholar = new function(){ } + /* + * PHP's in_array() for JS -- returns true if a value is contained in + * an array, false otherwise + */ + function inArray(needle, haystack){ + for (var i in haystack){ + if (haystack[i]==needle){ + return true; + } + } + return false; + } + + + /* + * PHP's array_search() for JS -- searches an array for a value and + * returns the key if found, false otherwise + */ + function arraySearch(needle, haystack){ + for (var i in haystack){ + if (haystack[i]==needle){ + return i; + } + } + return false; + } + + /** * Generate a random string of length 'len' (defaults to 8) **/