Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add solution for module 1: js basics #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion module-1/classification.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function grade(score) {
* Also take into consideration the documentation of the function!
*/
// PLACE YOUR CODE BETWEEN THIS...

gradeOfStudent = (score >= 0 && score <= 100) ? Math.max(Math.min(Math.floor(score / 10) - 4, 5), 1) : 0;
// ...AND THIS COMMENT LINE!
return gradeOfStudent;
}
Expand Down
16 changes: 14 additions & 2 deletions module-1/euclidean.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ function euclidean(a, b) {
* Also take into consideration the documentation of the function!
*/
// PLACE YOUR CODE BETWEEN THIS...


if (a > 0 && b > 0 && typeof (a) === 'number' && typeof (b) === 'number') {
while (a != b) {
if (a > b) {
a -= b;
}
else {
b -= a;
}
}
gcd = a;
}
else {
gcd = 0;
}
// ...AND THIS COMMENT LINE!
return gcd;
}
Expand Down
18 changes: 17 additions & 1 deletion module-1/fibonacci.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,23 @@ function fibonacci(n) {
* Also take into consideration the documentation of the function!
*/
// PLACE YOUR CODE BETWEEN THIS...

if (n >= 0) {
if (n < 2 && typeof (n) === 'number') {
nThFibonacci = n;
} else {
let f0 = 0;
let f1 = 1;
for (let i = 2; i <= n; ++i) {
const sum = f0 + f1;
f0 = f1;
f1 = sum;
}
nThFibonacci = f1;
}
}
else {
nThFibonacci = 0;
}
// ...AND THIS COMMENT LINE!
return nThFibonacci;
}
Expand Down