Make _.contains work with strings similar ES6 draft String#contains.

Former-commit-id: 3cfffdcddec3e1e8175da95043ec86ac3c6a85fe
This commit is contained in:
John-David Dalton
2012-07-11 01:11:25 -04:00
parent b9bade8d5a
commit cbdc9c0be1
4 changed files with 39 additions and 4 deletions

View File

@@ -514,10 +514,12 @@
data.firstArg = firstArg;
data.hasDontEnumBug = hasDontEnumBug;
data.isKeysFast = isKeysFast;
data.noCharByIndex = noCharByIndex;
data.shadowed = shadowed;
data.useHas = data.useHas !== false;
if (!('noCharByIndex' in data)) {
data.noCharByIndex = noCharByIndex;
}
if (!data.exit) {
data.exit = 'if (!' + firstArg + ') return result';
}
@@ -711,11 +713,21 @@
*
* _.contains([1, 2, 3], 3);
* // => true
*
* _.contains({ 'name': 'moe', 'age': 40 }, 'moe');
* // => true
*
* _.contains('curly', 'ur');
* // => true
*/
var contains = createIterator({
'args': 'collection, target',
'init': 'false',
'inLoop': 'if (iteratee[index] === target) return true'
'noCharByIndex': false,
'beforeLoop': {
'array': 'if (toString.call(iteratee) == stringClass) return collection.indexOf(target) > -1'
},
'inLoop': 'if (iteratee[index] === target) return true',
});
/**
@@ -2636,6 +2648,9 @@
*
* _.isEmpty({});
* // => true
*
* _.isEmpty('');
* // => true
*/
var isEmpty = createIterator({
'args': 'value',