Skip to content

Commit 1fa875f

Browse files
committed
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

+3-1
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)