Ajout première partie

This commit is contained in:
rick 2021-03-24 21:25:07 +01:00
parent 6a9a9220b7
commit ba6d6b5f5a
Signed by: Rick
GPG key ID: 2B593F087240EE99
2 changed files with 46 additions and 0 deletions

1
jour12/input Normal file

File diff suppressed because one or more lines are too long

45
jour12/jour12.js Normal file
View file

@ -0,0 +1,45 @@
const fs = require('fs');
const file = fs.readFileSync("input", "utf8");
const data = JSON.parse(file);
try {
console.log("Traitement de la première partie…");
console.log("La somme totate est " + parseJsonPrem(data));
} catch(err) {
console.log("Une erreur a été rencontrée !");
console.error(err);
}
function parseJsonPrem(obj) {
let ret = 0;
let value;
for (const index in obj) {
value = obj[index];
if (value instanceof Object) {
ret += parseJsonPrem(value);
} else if (Number.isInteger(value)) {
ret += value;
}
}
return ret;
}
/*
function parseObject(objet) {
let ret = 0;
let value;
for (const index in obj) {
value = obj[index];
if (value instanceof Array) {
ret += parseArray(value);
} else if (value instanceof Object) {
ret += parseObject(value);
} else if (Number.isInteger(value)) {
ret += value;
}
}
return ret;
}
*/