This task was given for a interview process.
Task was, given a CSV, find the ideal path to get the products, summing up where products were duplicated, and order them according to A - AZ, 1 - 10 for each alphabetical value.
- I knew i didn't know how to use/write CSV files are write a CLI program in node, so I looked into how to go about this, common libraries tutorials
- I looked at the data and how to approach the problem, what I might need, what I already knew.
- Set up a very basic function and built how to pass arguments to the functions.
- Once this was done, broke it down into steps
- Split the CSV into rows, and split that out into objects
- Make the objects easier to work with, remove duplicates (summing them) and adding the row and shelf values to make the next steps easier
- sort out alphabetical first
- sort out numerical order by grouping the alphabetical values
- clean the objects once completed, removing anything I'd added to complete the sorting
- convert the data back into a csv string ready to write
- write the file to a specific directory
- Document anything that wasn't documented completely
- Had a final run through, checked everything as best as I could and zipped this up for you
- Node.js
- whilst in the root of this project, run
npm i -g
which will install it globally on your system
- Chalk For making the terminal more readable for errors, warnings or successes
- Commander For ease of creating command line interfaces
- fs-extra for some additional features for writing the csv file, such as creating the directory if specified
- Mocha my usual test suite
- ESLint my usual linting standards
- Run the command
order sort ./path/to/csv/file
- to specify the directory you wish to write to,
order sort ./path/to/file -f ./path/to/save
defaults to application directory - To specify a delimiter for the CVS use
order sort ./path/to/file -d ;
defaults to,
- There is a test script, whilst in the directory run
npm test
to run the tests that are written - There is a eslint file to keep code up to standards
- I'd not actually used much of the file input for Node so this was a new thing to me
- I've accounted for commas at the end of a line, as well as whitespace. For a more feature complete, I would like to add ability to remove extra commas elsewhere
- There's two extra CSVs,
no_data.csv
andbad_data.csv
for some extra things
-
Whilst I have touched on Typescript, I haven't used it enough currently to be confident with it enough, so functions have used JSDoc for type hints
-
To perhaps add records of csv inputs, sqlite could be used and used to add reporting capabilities I would use the package
better-sqlite3
for this as it's very decent to use (for me) -
As mentioned, Node.js is a secondary language to me as my primary is PHP so hopefully this is all up to scratch!
-
Thank you for taking your time to look at this!