Ajout première partie
This commit is contained in:
parent
6a9a9220b7
commit
ba6d6b5f5a
2 changed files with 46 additions and 0 deletions
1
jour12/input
Normal file
1
jour12/input
Normal file
File diff suppressed because one or more lines are too long
45
jour12/jour12.js
Normal file
45
jour12/jour12.js
Normal 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;
|
||||
}
|
||||
*/
|
Loading…
Reference in a new issue