From 9e9a1af1efc790100370833889a82fb99a3bc9ac Mon Sep 17 00:00:00 2001 From: cristianpb Date: Thu, 8 Oct 2020 16:34:50 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Replace=20flat=20function=20to?= =?UTF-8?q?=20maintain=20support=20for=20firefox=2052?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/views/LinkCheck.svelte | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/components/views/LinkCheck.svelte b/src/components/views/LinkCheck.svelte index c0218b3f..f227841c 100644 --- a/src/components/views/LinkCheck.svelte +++ b/src/components/views/LinkCheck.svelte @@ -160,11 +160,34 @@ }); return r }) - .flat() + .map(row => flatten(row, 1)) .filter(row => !filter || row[header.indexOf('score')]) .map(row => header.map((col, i) => protectField(row[i])).join($linkCsvType.sep) + '\r\n')]; } + const flatten = (array, depth) => { + // If no depth is specified, default to 1 + if (depth === undefined) { + depth = 1; + } + + // Recursively reduce sub-arrays to the specified depth + const flat = (arr, depth) => { + + // If depth is 0, return the array as-is + if (depth < 1) { + return arr.slice(); + } + + // Otherwise, concatenate into the parent array + return arr.reduce(function (acc, val) { + return acc.concat(Array.isArray(val) ? flat(val, depth - 1) : val); + }, []); + + }; + return flat(array, depth); + }; + \ No newline at end of file +