Skip to content

Instantly share code, notes, and snippets.

@schalkneethling
Last active August 15, 2020 19:02
Show Gist options
  • Save schalkneethling/54d368363dfc75cd1e0633eae0fc565f to your computer and use it in GitHub Desktop.
Save schalkneethling/54d368363dfc75cd1e0633eae0fc565f to your computer and use it in GitHub Desktop.
What is the output in index.js?
const fs = require("fs");
const { update } = require("./util");
const entries = ["one", "two"];
function doUpdate() {
let fileContents = fs.readFileSync("./sample.json", "utf8");
fileContents = update(fileContents, entries);
console.log(entries); // what will this output?
}
doUpdate();
{
"entries": []
}
function update(fileContents, entries) {
const json = JSON.parse(fileContents);
entries.push("newEntry");
entries.forEach((entry) => {
json.entries.push(entry);
});
return JSON.stringify(json);
}
module.exports = {
update
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment