From 90b579afd0ea77cbf440ecb08fb8a3999c5160ac Mon Sep 17 00:00:00 2001 From: wangzemei Date: Thu, 12 Sep 2024 14:28:13 +0800 Subject: [PATCH] + [task#127427] add logic for flattenData func. --- lib/zin/wg/think3c/js/v1.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/zin/wg/think3c/js/v1.js b/lib/zin/wg/think3c/js/v1.js index 71a570a185..3c19477e50 100644 --- a/lib/zin/wg/think3c/js/v1.js +++ b/lib/zin/wg/think3c/js/v1.js @@ -299,6 +299,22 @@ function flattenData(data) const result = []; const stack = data.slice(); + while (stack.length > 0) + { + const item = stack.pop(); + if(typeof item === 'object' && item !== null && Object.prototype.toString.call(item) === '[object Array]') + { + for(let i = item.length - 1; i >= 0; i--) + { + stack.push(item[i]); + } + } + else + { + result.push(item); + } + } + return result; }