From b4cec3b138c30b2bbf808b27cd1f266e36bbd4f8 Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Sun, 8 Aug 2021 22:02:19 +0100 Subject: [PATCH] Parsing fixes --- index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b2ef8f4..f1415ef 100644 --- a/index.js +++ b/index.js @@ -3,17 +3,22 @@ const fs = require('fs'); const csvData = fs.readFileSync("data.csv", "utf-8"); function parseRows(data) { - let lines = data.split(","); + let lines = data.split("\n"); let headers = lines.shift().split(","); const out = []; for (const line of lines) { - const row = line.split(","); + if (!line) + continue; + + const row = line.split(","); const moves = []; for (let i = 0; i <= 7; i++) { - moves.push(row[headers.indexOf(`step_${i}_moves`)]); + let step = row[headers.indexOf(`step_${i}_moves`)]; + step = step.replace(/^[xyz]2 /, ""); + + moves.push(step); } - out.push({ scramble: row[headers.indexOf("scramble")], @@ -22,4 +27,5 @@ function parseRows(data) { } return out; } -console.log(JSON.stringify(parseRows(csvData))); \ No newline at end of file + +console.log(JSON.stringify(parseRows(csvData))); -- 2.30.5