Skip to content

Commit

Permalink
add function minor bugs are fixed and json writing is edited #4 from …
Browse files Browse the repository at this point in the history
…mertssmnoglu/mertssmnoglu_bug_fix-0

add function minor bugs are fixed and json writing is edited
  • Loading branch information
ismailcankaratas authored Jun 8, 2022
2 parents 91d1000 + 9f5f534 commit 6021bb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions operations/add.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
const writeDataJson = require("../helpers/writeDataJson");
const getAll = require('./getAll');
const log = require('../utils/log');

function add(arrayName, data) {
const newData = getAll();
newData[arrayName].push(data);
writeDataJson(JSON.stringify(newData));
if (newData[arrayName] != undefined) {
var isArray = newData[arrayName].constructor === Array ? true : false
if (isArray) {
newData[arrayName].push(data)
} else {
log(`${arrayName} is not an array.`, "Error", "error");
}
} else {
newData[arrayName] = []
newData[arrayName].push(data);
}
writeDataJson(JSON.stringify(newData, null, 4));
}


module.exports = add;

module.exports = add;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6021bb3

Please sign in to comment.