Created
November 26, 2021 02:43
-
-
Save tlcheah2/5d23eddc6f82d2725bc3146586574d5e to your computer and use it in GitHub Desktop.
getFileContents after refactor - Clean Code Chapter 3 Example
This file contains 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 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