Skip to content

Instantly share code, notes, and snippets.

@tlcheah2
Created November 26, 2021 02:43
Show Gist options
  • Save tlcheah2/5d23eddc6f82d2725bc3146586574d5e to your computer and use it in GitHub Desktop.
Save tlcheah2/5d23eddc6f82d2725bc3146586574d5e to your computer and use it in GitHub Desktop.
getFileContents after refactor - Clean Code Chapter 3 Example
const fs = require('fs');
function readCsvFile() {
return fs.readFileSync('./random-word.csv', { encoding: 'utf8' });
}
function parseFileContent(content) {
return content.split(',').map((word) => {
return word.trim();
});
}
function getFileContents() {
const content = readCsvFile();
return parseFileContent(content);
}
console.log('Start reading file');
console.log('file contents', getFileContents());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment