Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1fa875f

Browse files
feat(linkedList): takes iterables in the constructor
1 parent f3fe049 commit 1fa875f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎src/data-structures/linked-lists/linked-list.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ const Node = require('./node');
77
* the last and first element
88
*/
99
class LinkedList {
10-
constructor() {
10+
constructor(iterable=[]) {
1111
this.first = null; // head/root element
1212
this.last = null; // last element of the list
1313
this.size = 0; // total number of elements in the list
14+
15+
Array.from(iterable, (i) => this.addLast(i));
1416
}
1517
// end::constructor[]
1618

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /