From f954df3fe993ea9ab99f9bcc56b7fc2779f269d1 Mon Sep 17 00:00:00 2001 From: Rangga Fajar Oktariansyah <86386385+FajarKim@users.noreply.github.com> Date: Sat, 29 Jun 2024 06:02:35 +0700 Subject: [PATCH] fix: update similar results in python (#3) --- index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 5a7ed42..d2989cc 100644 --- a/index.js +++ b/index.js @@ -8,14 +8,16 @@ * @return {Array} The array of lines, with or without line breaks based on the `keeplinebreaks` parameter. */ String.prototype.splitLines = function(keeplinebreaks = false) { + const array = this.split(/(\r?\n|\r|\n)/).reduce((acc, curr, index, array) => { + if (index % 2 === 0) { + acc.push(curr + (array[index + 1] || "")); + } + return acc; + }, []).filter(Boolean); + if (keeplinebreaks === true) { - return this.split(/(\r?\n|\r|\n)/).reduce((acc, curr, index, array) => { - if (index % 2 === 0) { - acc.push(curr + (array[index + 1] || "")); - } - return acc; - }, []).filter(Boolean); + return array; } else { - return this.split(/\r?\n|\r|\n/).filter(Boolean); + return array.map(line => line.replace(/\r?\n|\r|\n/g, "")); } }