Skip to content

Commit

Permalink
Files and Folders update
Browse files Browse the repository at this point in the history
  • Loading branch information
diberry committed Dec 14, 2023
1 parent 096ca5e commit e3564e2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions nodejs-debug/fibonacci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function fibonacci(n) {
let n1 = 0;
let n2 = 1;
let sum = 0;

const json = {
n1,
n2,
sum,
};

for (let i = 2; i <= n; i++) {
sum = n1 + n2;
n1 = n2;
n2 = sum;
}

return n === 0 ? n1 : n2;
}

const result = fibonacci(5);
console.log(result);
21 changes: 21 additions & 0 deletions nodejs-files/index-unit-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require("path");
const fs = require("fs").promises;

let results = []

async function findFiles(folderName) {
results.push(`${folderName}`);

const relativePathToFolder = path.join(__dirname, folderName);
const items = await fs.readdir(relativePathToFolder, { withFileTypes: true });

for (const item of items) {
if (item.isDirectory()) {
await findFiles(`${folderName}/${item.name}`);
} else {
results.push(`${folderName}/${item.name}`);
}
}
}

findFiles("stores").then(() => console.log(results));

0 comments on commit e3564e2

Please sign in to comment.