From 3f30cef651264b8014fc1896f0dec3039794c368 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Thu, 20 Jun 2024 16:25:39 +0930 Subject: [PATCH] change(utils): use Array.flat() in flatten() --- lib/utils.js | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index d19311f..3dea45e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -98,25 +98,4 @@ exports.reduce = nodes => nodes.reduce((acc, node) => { * Flatten an array */ -exports.flatten = (...args) => { - const result = []; - - const flat = arr => { - for (let i = 0; i < arr.length; i++) { - const ele = arr[i]; - - if (Array.isArray(ele)) { - flat(ele); - continue; - } - - if (ele !== undefined) { - result.push(ele); - } - } - return result; - }; - - flat(args); - return result; -}; +exports.flatten = (...args) => args.flat(Infinity);