Skip to content

Commit

Permalink
Iterate using array.length instead of for..in
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Feldman committed May 6, 2015
1 parent 280f8c8 commit af6a8df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
16 changes: 10 additions & 6 deletions seamless-immutable.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@
return this;
}

var result = [];
var result = [],
length = this.length,
index;

for (var key in this) {
var iteratorResult = iterator(this[key], parseInt(key), this);
for (index = 0; index < length; index++) {
var iteratorResult = iterator(this[index], index, this);

if (iteratorResult instanceof Array) {
// Concatenate Array results into the return value we're building up.
Expand Down Expand Up @@ -192,10 +194,12 @@
iterator = function(value) { return value; };
}

var result = {};
var result = {},
length = this.length,
index;

for (var index in this) {
var pair = iterator(this[index], parseInt(index), this),
for (index = 0; index < length; index++) {
var pair = iterator(this[index], index, this),
key = pair[0],
value = pair[1];

Expand Down
2 changes: 1 addition & 1 deletion seamless-immutable.production.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions src/seamless-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@
return this;
}

var result = [];
var result = [],
length = this.length,
index;

for (var key in this) {
var iteratorResult = iterator(this[key], parseInt(key), this);
for (index = 0; index < length; index++) {
var iteratorResult = iterator(this[index], index, this);

if (iteratorResult instanceof Array) {
// Concatenate Array results into the return value we're building up.
Expand Down Expand Up @@ -192,10 +194,12 @@
iterator = function(value) { return value; };
}

var result = {};
var result = {},
length = this.length,
index;

for (var index in this) {
var pair = iterator(this[index], parseInt(index), this),
for (index = 0; index < length; index++) {
var pair = iterator(this[index], index, this),
key = pair[0],
value = pair[1];

Expand Down

0 comments on commit af6a8df

Please sign in to comment.