mirror of
https://github.com/hanzoai/es5-ext.git
synced 2026-09-24 16:58:43 +00:00
Array#keys (as implemented in ES 6)
This commit is contained in:
@@ -56,6 +56,7 @@ It's about properties introduced with ES6 and those that have been updated in ne
|
||||
- `Array.prototype.filter` -> `require('es5-ext/array/#/filter')`
|
||||
- `Array.prototype.find` -> `require('es5-ext/array/#/find')`
|
||||
- `Array.prototype.findIndex` -> `require('es5-ext/array/#/find-index')`
|
||||
- `Array.prototype.keys` -> `require('es5-ext/array/#/keys')`
|
||||
- `Array.prototype.map` -> `require('es5-ext/array/#/map')`
|
||||
- `Array.prototype.slice` -> `require('es5-ext/array/#/slice')`
|
||||
- `Array.prototype.splice` -> `require('es5-ext/array/#/splice')`
|
||||
@@ -287,6 +288,11 @@ Returns true if both context and _other_ lists have same content
|
||||
|
||||
Returns true if all values in array are unique
|
||||
|
||||
#### arr.keys() _(es5-ext/array/#/keys)_
|
||||
|
||||
[_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.keys).
|
||||
Return iterator object, where each iterated value represents array index.
|
||||
|
||||
#### arr.last() _(es5-ext/array/#/last)_
|
||||
|
||||
Returns value of last defined index
|
||||
|
||||
@@ -20,6 +20,7 @@ module.exports = {
|
||||
firstIndex: require('./first-index'),
|
||||
flatten: require('./flatten'),
|
||||
forEachRight: require('./for-each-right'),
|
||||
keys: require('./keys'),
|
||||
group: require('./group'),
|
||||
indexesOf: require('./indexes-of'),
|
||||
intersection: require('./intersection'),
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
if (!require('./is-implemented')()) {
|
||||
Object.defineProperty(Array.prototype, 'keys', { value: require('./shim'),
|
||||
configurable: true, enumerable: false, writable: true });
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./is-implemented')() ?
|
||||
Array.prototype.keys : require('./shim');
|
||||
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function () {
|
||||
var arr = [1, 'foo'], iterator, result;
|
||||
if (typeof arr.keys !== 'function') return false;
|
||||
iterator = arr.keys();
|
||||
if (!iterator) return false;
|
||||
if (typeof iterator.next !== 'function') return false;
|
||||
result = iterator.next();
|
||||
if (!result) return false;
|
||||
if (result.value !== 0) return false;
|
||||
if (result.done !== false) return false;
|
||||
return true;
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
var ArrayIterator = require('es6-iterator/array');
|
||||
module.exports = function () { return new ArrayIterator(this, 'key'); };
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var isImplemented = require('../../../../array/#/keys/is-implemented');
|
||||
|
||||
module.exports = function (a) { a(isImplemented(), true); };
|
||||
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./shim');
|
||||
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (t, a) { a(typeof t(), 'boolean'); };
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
exports.__generic = function (t, a) {
|
||||
var iterator = t.call(this);
|
||||
a.deep(iterator.next(), { value: 0, done: false });
|
||||
a.deep(iterator.next(), { value: 1, done: false });
|
||||
a.deep(iterator.next(), { value: 2, done: false });
|
||||
a.deep(iterator.next(), { value: undefined, done: true });
|
||||
};
|
||||
Reference in New Issue
Block a user