- Notifications
You must be signed in to change notification settings - Fork 273
Add: fibonacci memoization in JavaScript #249
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
| @@ -560,11 +560,6 @@ Com o objetivo de alcançar uma abrangência maior e encorajar mais pessoas a co | |||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- JavaScript --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- Swift --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
| @@ -993,6 +988,63 @@ Com o objetivo de alcançar uma abrangência maior e encorajar mais pessoas a co | |||||
</td> | ||||||
</tr> | ||||||
<tr> | ||||||
<td><a href="https://www.ime.usp.br/~pf/algoritmos/aulas/recu.html">Fibonacci Memoization</a></td> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggested change
| ||||||
<td> <!-- C --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- C++ --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- Java --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- Python --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- Go --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- Ruby --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!--JavaScript--> | ||||||
<a href="./src/javascript/FibonacciMemoization.js"> | ||||||
<img align="center" height="25" src="./logos/javascript.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- Swift --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- Rust --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- Scala --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
<td> <!-- Kotlin --> | ||||||
<a href="./CONTRIBUTING.md"> | ||||||
<img align="center" height="25" src="./logos/github.svg" /> | ||||||
</a> | ||||||
</td> | ||||||
</tr> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation is wrong, I believe you should add 4 spaces. | ||||||
<td><a href="https://www.ime.usp.br/~pf/algoritmos/aulas/recu.html">Máximo Recursivo</a></td> | ||||||
<td> <!-- C --> | ||||||
<a href="./src/c/MaxRecursivo.c"> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* A memoização é uma abordagem que podemos usar para escrever a função fibonacci. Resumindo é uma técnica de otimização em que amarzenamos os valores de resultados anteriores, de modo semelhante a um cache. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please translate it to english? | ||
* | ||
* @param {number} n | ||
*/ | ||
function fibonacciMemoization(n) { | ||
const memo = [0, 1]; | ||
const fibonacci = (n) => { | ||
if(memo[n] != null) return memo[n]; | ||
return memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo) | ||
}; | ||
| ||
return fibonacci; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this
<td>
?