Skip to content

Commit

Permalink
Revert to wiki version of Array.from / .of.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Dec 25, 2011
1 parent 80d4f10 commit 31ac1e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
21 changes: 17 additions & 4 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,21 @@
});

defineProperties(Array, {
of: function(iterable) {
return Array.prototype.slice.call(iterable);
from: function(iterable) {
var object = Object(iterable);
var array = [];

for (var key = 0, length = object.length >>> 0; key < length; key++) {
if (key in object) {
array[key] = object[key];
}
}

return array;
},

of: function() {
return Array.prototype.slice.call(arguments);
}
});

Expand Down Expand Up @@ -203,7 +216,7 @@
})()
});

defineProperties(globall.Set, {
/*defineProperties(globall.Set, {
of: function(iterable) {
var object = Object(iterable);
var set = Set();
Expand All @@ -216,5 +229,5 @@
return set;
}
});
});*/
});
14 changes: 10 additions & 4 deletions test/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ var expect = require('expect.js');
require('../');

describe('Array', function() {
describe('Array.of()', function() {
describe('Array.from()', function() {
it('should create correct array from iterable', function() {
(function() {
expect(Array.of(arguments)).to.eql([0, 1, 2])
expect(Array.from(arguments)).to.eql([0, 1, 2])
})(0, 1, 2);

(function() {
expect(Array.of(arguments)).to.eql([null, undefined, 0.1248, -0, 0]);
expect(Array.from(arguments)).to.eql([null, undefined, 0.1248, -0, 0]);
})(null, undefined, 0.1248, -0, 0);
});

it('should handle empty iterables correctly', function() {
(function() {
expect(Array.of(arguments)).to.eql([]);
expect(Array.from(arguments)).to.eql([]);
})();
});
});

describe('Array.of()', function() {
it('should create correct array from arguments', function() {
expect(Array.of(1, null, void 0)).to.eql([1, null, void 0])
});
});
});

0 comments on commit 31ac1e3

Please sign in to comment.