2014-11-16 01:29:07 +01:00
|
|
|
/**
|
|
|
|
* Array utilities
|
|
|
|
*/
|
|
|
|
|
2016-05-20 10:08:39 +02:00
|
|
|
import {matchCase} from './string';
|
2014-11-16 01:29:07 +01:00
|
|
|
|
2016-05-25 09:31:53 +02:00
|
|
|
/**
|
|
|
|
* Checks if given item can be found in the passed collection
|
|
|
|
* @param {Array} arr collection
|
|
|
|
* @param {Any} val item to search
|
|
|
|
* @param {Boolean} caseSensitive respects case if true
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
2016-05-20 08:58:54 +02:00
|
|
|
export const has = (arr, val, caseSensitive) => {
|
|
|
|
let sCase = Boolean(caseSensitive);
|
|
|
|
for (var i = 0, l = arr.length; i < l; i++) {
|
2016-05-20 10:08:39 +02:00
|
|
|
if (matchCase(arr[i].toString(), sCase) === val) {
|
2016-05-20 08:58:54 +02:00
|
|
|
return true;
|
2014-11-16 01:29:07 +01:00
|
|
|
}
|
|
|
|
}
|
2016-05-20 08:58:54 +02:00
|
|
|
return false;
|
|
|
|
}
|