Skip to content

Add concat() method #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,18 @@ Collection.prototype.all = function () {
return this.items;
};

Collection.prototype.concat = function (collection) {
if (collection instanceof Collection) {
collection = collection.all();
}

for (let iterator = 1; iterator <= collection.count(); iterator++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use forEach instead of a loop

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with forEach in Javascript is that order can be messed up, right? I think keeping order is important.

https://stackoverflow.com/questions/13600922/does-javascript-array-foreach-traverse-elements-in-ascending-order

this.items.push(collection[iterator]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs logic for when item is of different type

  • Array
  • Object
  • String
  • etc.

}

return this;
};

module.exports = function (collection) {
return new Collection(collection);
};
};