Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions bin/factorial/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env node

import readline from "readline";
import { countFactorial } from "../../src/functional/factorial.js";
import { Factorial } from "../../src/oop/Factorial.js";
import { validateApproach } from "../../src/utils/validateApproach.js";
import { validateFactorialMethod } from "../../src/utils/validateMethod.js";
import { validateInputNumber } from "../../src/utils/validateInput.js";

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

rl.question("Select the factorial approach (functional / oop) : ", approach => {
validateApproach(approach);

rl.question("Select the factorial method (loop / recursive) : ", method => {
validateFactorialMethod(method);

rl.question("Input the number : ", number => {
validateInputNumber(number);

let result = 0;

if (approach == "functional") {
result = countFactorial(number, method);
}

if (approach == "oop") {
result = new Factorial(number).count(method);
}

console.log(`------count factorial using ${method} (${approach})------`);
console.log(`factorial of ${number} is ${result}`);

rl.close();
});
});
});
43 changes: 43 additions & 0 deletions bin/fibonacci/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node

import readline from "readline";
import { generateFibonacci } from "../../src/functional/fibonacci.js";
import { Fibonacci } from "../../src/oop/Fibonacci.js";
import { validateApproach } from "../../src/utils/validateApproach.js";
import { validateFibonacciMethod } from "../../src/utils/validateMethod.js";
import { validateInputNumber } from "../../src/utils/validateInput.js";

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

rl.question("Select the fibonacci approach (functional / oop) : ", approach => {
validateApproach(approach);

rl.question("Select the fibonacci method (loop / recursive) : ", method => {
validateFibonacciMethod(method);

rl.question("Input the sequence : ", sequence => {
validateInputNumber(sequence);

let result = [];

if (approach == "functional") {
result = generateFibonacci(sequence, method);
}

if (approach == "oop") {
result = new Fibonacci(sequence).generate(method);
}

console.log(
`------generate fibonacci using ${method} (${approach})------`,
);
console.log(`fibonacci array with ${sequence} sequence : `);
console.log(result);

rl.close();
});
});
});
36 changes: 36 additions & 0 deletions bin/fizzbuzz/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env node

import readline from "readline";
import { FizzBuzz } from "../../src/oop/FizzBuzz.js";
import { generateFizzBuzz } from "../../src/functional/fizz-buzz.js";
import { validateApproach } from "../../src/utils/validateApproach.js";
import { validateInputNumber } from "../../src/utils/validateInput.js";

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

rl.question("Select the fizz-buzz approach (functional / oop) : ", approach => {
validateApproach(approach);

rl.question("Input the sequence : ", sequence => {
validateInputNumber(sequence);

let result = 0;

if (approach == "functional") {
result = generateFizzBuzz(sequence);
}

if (approach == "oop") {
result = new FizzBuzz(sequence).generate();
}

console.log(`------generate fizzbuzz (${approach})------`);
console.log(`fizzbuzz array with ${sequence} sequence : `);
console.log(result);

rl.close();
});
});
49 changes: 49 additions & 0 deletions bin/palindrome/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env node

import readline from "readline";
import { generatePalindromeStatus } from "../../src/functional/palindrome.js";
import { Palindrome } from "../../src/oop/Palindrome.js";
import { validateApproach } from "../../src/utils/validateApproach.js";
import {
validateFactorialMethod,
validatePalindromeMethod,
} from "../../src/utils/validateMethod.js";

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

rl.question(
"Select the palindrome approach (functional / oop) : ",
approach => {
validateApproach(approach);

rl.question(
"Select the palindrome method (reverse / loop / recursive) : ",
method => {
validatePalindromeMethod(method);

rl.question("Input the word : ", word => {
let result = 0;

if (approach == "functional") {
result = generatePalindromeStatus(word, method);
}

if (approach == "oop") {
result = new Palindrome(word).generateStatus(method);
}

console.log(
`------generate palindrom status using ${method} (${approach})------`,
);
console.log(`is ${word} a palindrome?`);
console.log(result);

rl.close();
});
},
);
},
);
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@
"type": "module",
"version": "1.0.0",
"description": "Learn to code with version control system using Git.",
"bin": {
"factorial": "./bin/factorial/index.js",
"fibonacci": "./bin/fibonacci/index.js",
"fizzbuzz": "./bin/fizzbuzz/index.js",
"palindrome": "./bin/palindrome/index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"factorial": "node ./bin/factorial/index.js",
"fibonacci": "node ./bin/fibonacci/index.js",
"fizzbuzz": "node ./bin/fizzbuzz/index.js",
"palindrome": "node ./bin/palindrome/index.js"
},
"repository": {
"type": "git",
Expand Down
136 changes: 68 additions & 68 deletions pages/functional/factorial.html
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RWID Git - Factorial</title>
<link
rel="shortcut icon"
href="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
type="image/x-icon"
/>
<link rel="stylesheet" href="../css/index.css" />
</head>

<body>
<main class="main-container">
<h1>Factorial (Functional)</h1>
<form id="form">
<div class="input-number-container">
<label for="n">Input the n number</label>
<input
type="number"
name="n"
id="n"
min="0"
step="1"
required="required"
/>
</div>

<div class="method-container">
<label>Choose the method</label>

<label for="method-loop" class="method-item">
<input
type="radio"
name="method"
id="method-loop"
value="loop"
required="required"
/>
<span>Loop</span></label
>
<label for="method-recursive" class="method-item">
<input
type="radio"
name="method"
id="method-recursive"
value="recursive"
required="required"
/>
<span>Recursive</span></label
>
</div>

<button type="submit">Count Factorial</button>
</form>

<p>
<strong>Result: <span id="result">-</span></strong>
</p>

<p><a href="/">Back to Homepage</a></p>
</main>

<script type="module" src="./js/factorial.js"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RWID Git - Factorial</title>
<link
rel="shortcut icon"
href="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
type="image/x-icon"
/>
<link rel="stylesheet" href="../css/index.css" />
</head>
<body>
<main class="main-container">
<h1>Factorial (Functional)</h1>
<form id="form">
<div class="input-number-container">
<label for="n">Input the n number</label>
<input
type="number"
name="n"
id="n"
min="0"
step="1"
required="required"
/>
</div>
<div class="method-container">
<label>Choose the method</label>
<label for="method-loop" class="method-item">
<input
type="radio"
name="method"
id="method-loop"
value="loop"
required="required"
/>
<span>Loop</span></label
>
<label for="method-recursive" class="method-item">
<input
type="radio"
name="method"
id="method-recursive"
value="recursive"
required="required"
/>
<span>Recursive</span></label
>
</div>
<button type="submit">Count Factorial</button>
</form>
<p>
<strong>Result: <span id="result">-</span></strong>
</p>
<p><a href="/">Back to Homepage</a></p>
</main>
<script type="module" src="./js/factorial.js"></script>
</body>
</html>
Loading