Scholar.inArray(needle, haystack) and Scholar.arraySearch(needle, haystack) -- versions of the PHP functions for JS
This commit is contained in:
parent
6b002f7566
commit
6c89acbe0d
1 changed files with 30 additions and 0 deletions
|
@ -23,6 +23,8 @@ var Scholar = new function(){
|
||||||
this.getString = getString;
|
this.getString = getString;
|
||||||
this.flattenArguments = flattenArguments;
|
this.flattenArguments = flattenArguments;
|
||||||
this.join = join;
|
this.join = join;
|
||||||
|
this.inArray = inArray;
|
||||||
|
this.arraySearch = arraySearch;
|
||||||
this.randomString = randomString;
|
this.randomString = randomString;
|
||||||
this.getRandomID = getRandomID;
|
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)
|
* Generate a random string of length 'len' (defaults to 8)
|
||||||
**/
|
**/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue