These are the projects for the JavaScript Level 2 module in Learn JS the Hard Way.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
js-level-2-projects/01-parse-a-csv-file
Zed A. Shaw 8cd18c6f8c More explanation of all the projects in the README files. 2 years ago
..
README.md More explanation of all the projects in the README files. 2 years ago
package-lock.json Quick empty markers for each directory so git thinks they exist. 2 years ago
package.json Implement step4 as a demo of how to deal with APIs that don't understand async using a promise. Remove useless await on simple_parse. 2 years ago
step1.js Implement step4 as a demo of how to deal with APIs that don't understand async using a promise. Remove useless await on simple_parse. 2 years ago
step2.js Implement step4 as a demo of how to deal with APIs that don't understand async using a promise. Remove useless await on simple_parse. 2 years ago
step3.js One more step in the process to learn about converting callbacks with promises. 2 years ago
step4.js One more step in the process to learn about converting callbacks with promises. 2 years ago
step5.js One more step in the process to learn about converting callbacks with promises. 2 years ago
step6.js Simple README.md explaining the exercise code. 2 years ago

README.md

Exercise 01: CSV is Easy...Right?

This is exercise 01 of JavaScript Level 2 in Learn JavaScript the Hard Way. It is meant to be done as a challenge with incorrect starting code that you are expected to fix and improve. I repeat, this code is incorrect on purpose so you can fix it and attempt to do better.

  • step1.js -- Use two projects to get CSV samples and try to write a simple parser that can parse all of the samples.
  • step2.js -- This is a starter in case you are stuck, but it still fails and would fail on many CSV files. CSV is more complex than its name lets on.
  • step3.js -- Take your parser and use the deep-equal project to compare your results to the csv-spectrum project's tests.
  • step4.js -- Let's up the game and make this a unit test with ava, except it doesn't work because of promises/async/await not working with callbacks and events.
  • step5.js -- First solution to step4.js that uses Promise directly to wrap callbacks and events.
  • step6.js -- Second solution that uses util.promisify to convert the spectrum callback to a Promise automatically.

If you attempt this challenge then point me at your solution at @lzsthw and I'll take a look.

Learning Objectives

You aren't really learning about CSVs, but actually learning about how to deal with old APIs that use callbacks when you need Promises. The csv-spectrum library uses an old style of operation that loads your data then calls a function for you to process the data. These days APIs need Promises, and use async/await to deal with the promises. Using what you learned from the previous module JavaScript Level 1 you learned quite a lot about async/await/Promise/callbacks so now you apply that knowledge to deal with csv-spectrum.

If You Get Stuck

Remember the programming process of:

  1. Write comments in human language describing what the code should do.
  2. Write pseudo-code (p-code) under those comments to bridge from human to code.
  3. Slowly convert the p-code to JavaScript and run your script repeatedly while you do.

If you're stuck chances are you're not following this process. If you need a clue about how to handle the csv-spectrum API then jump to the step5.js file to see one way, and step6.js to see another. Try to figure it out for yourself, and if you want a clue, remember that the resolve parameter to a Promise can be called inside a callback.