From d85785b54026a6c3e93359e84898aa9f6022d4c7 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 15 Apr 2020 20:23:45 +0300 Subject: [PATCH] Fix a bug with nest snippet Pass `link` to nested `nest` call. Resolves #1116. --- snippets/nest.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/nest.md b/snippets/nest.md index 56b5094fa..6167d5dfd 100644 --- a/snippets/nest.md +++ b/snippets/nest.md @@ -15,7 +15,7 @@ Omit the third argument, `link`, to use `'parent_id'` as the default property wh const nest = (items, id = null, link = 'parent_id') => items .filter(item => item[link] === id) - .map(item => ({ ...item, children: nest(items, item.id) })); + .map(item => ({ ...item, children: nest(items, item.id, link) })); ``` ```js @@ -28,4 +28,4 @@ const comments = [ { id: 5, parent_id: 4 } ]; const nestedComments = nest(comments); // [{ id: 1, parent_id: null, children: [...] }] -``` \ No newline at end of file +```