This commit is contained in:
Aelita4 2022-12-08 00:20:25 +01:00
parent 3bdc7267c0
commit f2110e97af
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
1 changed files with 34 additions and 0 deletions

View File

@ -90,3 +90,37 @@ function part1(currentFolders) {
console.log(part1(root.folders))
console.log("=== PART 2 ===");
function part2(currentFolders) {
const arr = [];
for(const [folderName, folderObj] of Object.entries(currentFolders)) {
arr.push(...part2(folderObj.folders));
arr.push({
name: folderObj.path,
size: folderObj.getCurrentDirectorySize()
})
}
return arr;
}
const total = 70_000_000;
const required = 30_000_000;
let free = total - root.getCurrentDirectorySize();
let toDelete = required - free;
const part2Array = part2(root.folders);
part2Array.sort((a, b) => b.size - a.size);
let sizeOfSmallestDeletableDirectory = 0;
part2Array.forEach(folder => {
if(toDelete - folder.size < 0) sizeOfSmallestDeletableDirectory = folder.size;
});
console.log(sizeOfSmallestDeletableDirectory);