From 840635e613c13b5dfd135b3dfc48eb4057783c05 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Mon, 9 Apr 2018 19:43:09 +0300 Subject: [PATCH] Add playground. --- src/data-structures/linked-list/LinkedList.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/data-structures/linked-list/LinkedList.js b/src/data-structures/linked-list/LinkedList.js index d4ab790c..66dbdb90 100644 --- a/src/data-structures/linked-list/LinkedList.js +++ b/src/data-structures/linked-list/LinkedList.js @@ -133,15 +133,19 @@ export default class LinkedList { return deletedHead; } - toString(callback) { - const nodeStrings = []; + toArray() { + const nodes = []; let currentNode = this.head; while (currentNode) { - nodeStrings.push(currentNode.toString(callback)); + nodes.push(currentNode); currentNode = currentNode.next; } - return nodeStrings.toString(); + return nodes; + } + + toString(callback) { + return this.toArray().map(node => node.toString(callback)).toString(); } }