10000 Merge branch 'main' into main · daygoDao/javascript-exercises@a27f662 · GitHub
[go: up one dir, main page]

Skip to content

Commit a27f662

Browse files
Merge branch 'main' into main
2 parents 80ca665 + a3992aa commit a27f662

File tree

6 files changed

+4458
-4721
lines changed

6 files changed

+4458
-4721
lines changed

10_fibonacci/solution/fibonacci-solution.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ const fibonacci = function(countArg) {
1313

1414
let firstPrev = 1;
1515
let secondPrev = 0;
16-
16+
1717
for (let i = 2; i <= count; i++) {
1818
let current = firstPrev + secondPrev;
1919
secondPrev = firstPrev;
2020
firstPrev = current;
2121
}
2222

2323
return firstPrev;
24+
2425
};
2526

26-
module.exports = fibonacci;
27+
// Another way to do it is by using an iterative approach with an array containing two values, 0 and 1.
28+
// const fib = [0, 1];
29+
// for (let i = 2; i <= count; i++) {
30+
// fib[i] = fib[i - 1] + fib[i - 2];
31+
// }
32+
// return fib[count];
33+
34+
module.exports = fibonacci;

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ If you have a suggestion to improve an exercise, an idea for a new exercise, or
1515
- Copies of repositories on your machine are called clones. If you need help cloning to your local environment you can learn how from the GitHub documentation on [cloning a repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository-from-github/cloning-a-repository).
1616
2. Before you start working on any exercises, you should first ensure you have the following installed:
1717
- **NPM**. You should have installed NPM already in our [Installing Node.js](https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installing-node-js) lesson. Just in case you need to check, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, **do not follow the instructions in the terminal** to install with `apt-get` as this causes permission issues. Instead, go back to the installation lesson and install Node with NVM by following the instructions there.
18-
- **Jest**. After cloning this repository to your local machine and installing NPM, go into the newly created directory 5553 (`cd javascript-exercises`) and run `npm install`. This will install Jest and set up the testing platform based on our preconfigured settings.
18+
- **Jest**. After cloning this repository to your local machine and installing NPM, go into the newly created directory (`cd javascript-exercises`) and run `npm install`. This will install Jest and set up the testing platform based on our preconfigured settings. (Note: if you get warnings that packages are out of date or contain vulnerabilities, you can safely ignore them for these exercises.)
19+
1920
3. Each exercise includes the following:
2021

2122
- A markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests.

0 commit comments

Comments
 (0)
0