Created
October 29, 2019 05:04
-
-
Save joeyklee/151b94fc809f2766bdf13eeabd675c68 to your computer and use it in GitHub Desktop.
quick demo for diary parser for student
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const entries = ` | |
10/12/2018 (Vancouver, Canada) | |
Today I flew to Vancouver and it was my first time in Canada. I can't believe how beautiful it is here. | |
My favorite thing about the city is how green it is and how beautiful the mountains are. I also love being on the ocean. | |
10/28/2019 (New York City, USA) | |
I'm writing this from my apartment in New York City. I recently started going to ITP, the coolest program ever! | |
01/10/22 (Berlin, Germany) | |
This is just a check in from Berlin. Hällo! | |
` | |
function newEntry(){ | |
return { | |
date: "", | |
location: "", | |
text: "" | |
} | |
} | |
const entriesArray = entries.split('\n') | |
filteredEntries = entriesArray.filter( row => row !== "") | |
let output = []; | |
let currentEntry; | |
filteredEntries.forEach( row => { | |
if( row.split(' ')[0].includes('/')){ | |
currentEntry = newEntry(); | |
const item = row.split(' ') | |
currentEntry.date = item[0] | |
currentEntry.location = item[1].replace("(", "") + item[2].replace(")", "") | |
output.push(currentEntry); | |
} else { | |
currentEntry.text += row | |
} | |
}) | |
console.log(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment