From 351ce48f645efe85108812c691f99e2f3b9800a1 Mon Sep 17 00:00:00 2001 From: taimoor Date: Tue, 22 Sep 2020 17:37:22 +0500 Subject: [PATCH] update name for external accumulator. --- snippets/unflattenObject.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/unflattenObject.md b/snippets/unflattenObject.md index c235eba4c..a030d7f9d 100644 --- a/snippets/unflattenObject.md +++ b/snippets/unflattenObject.md @@ -11,11 +11,11 @@ Unflatten an object with the paths for keys. - Otherwise, add the appropriate key-value pair to the accumulator object and return value as the accumulator. ```js const unflattenObject = obj =>{ - return Object.keys(obj).reduce((acc1 , k)=>{ + return Object.keys(obj).reduce((res , k)=>{ k.split('.').reduce(function(acc, e, i , keys) { return acc[e] || (acc[e] = isNaN(Number(keys[i + 1])) ? (keys.length - 1 === i ? obj[k] : {}) : []); - }, acc1) - return acc1; + }, res) + return res; },{}); } ```