Skip to content

Commit 7d178b8

Browse files
add fibonacci sequence and fisher-yates
1 parent 46249bc commit 7d178b8

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@
3131
1. [Шифр Цезаря / Caesar Cipher](https://github.com/dmitrymorozoff/algorithms-in-javascript/blob/master/source/cryptographic/caesar-cipher/caesar-cipher.js) | [Инфо](https://ru.wikipedia.org/wiki/%D0%A8%D0%B8%D1%84%D1%80_%D0%A6%D0%B5%D0%B7%D0%B0%D1%80%D1%8F)
3232

3333
## Другое / Other
34-
1. [Решето Эратосфена / Sieve Of Eratosthenes](https://github.com/dmitrymorozoff/algorithms-in-javascript/blob/master/source/other/sieve-of-eratosthenes.js) | [Инфо](https://ru.wikipedia.org/wiki/%D0%A0%D0%B5%D1%88%D0%B5%D1%82%D0%BE_%D0%AD%D1%80%D0%B0%D1%82%D0%BE%D1%81%D1%84%D0%B5%D0%BD%D0%B0)
34+
1. [Решето Эратосфена / Sieve Of Eratosthenes](https://github.com/dmitrymorozoff/algorithms-in-javascript/blob/master/source/other/sieve-of-eratosthenes/sieve-of-eratosthenes.js) | [Инфо](https://ru.wikipedia.org/wiki/%D0%A0%D0%B5%D1%88%D0%B5%D1%82%D0%BE_%D0%AD%D1%80%D0%B0%D1%82%D0%BE%D1%81%D1%84%D0%B5%D0%BD%D0%B0)
35+
2. [Тасование Фишера — Йетса / Fisher–Yates Shuffle](https://github.com/dmitrymorozoff/algorithms-in-javascript/blob/master/source/other/fisher-yates/fisher-yates.js) | [Инфо](http://wiki-org.ru/wiki/%D0%A2%D0%B0%D1%81%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_%D0%A4%D0%B8%D1%88%D0%B5%D1%80%D0%B0%E2%80%93%D0%99%D0%B5%D1%82%D1%81%D0%B0)
36+
3. [Числа Фибоначчи / Fibonacci Sequence](https://github.com/dmitrymorozoff/algorithms-in-javascript/blob/master/source/other/fibonacchi/fibonacchi.js) | [Инфо](https://ru.wikipedia.org/wiki/%D0%A7%D0%B8%D1%81%D0%BB%D0%B0_%D0%A4%D0%B8%D0%B1%D0%BE%D0%BD%D0%B0%D1%87%D1%87%D0%B8)
37+

index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
<script src="./source/search/binary-search/binary-search.js" type="module"></script>
2323
<script src="./source/hash-table/hash-table.js" type="module"></script>
2424
<script src="./source/cryptographic/caesar-cipher/caesar-cipher.js" type="module"></script>
25+
<script src="./source/other/fisher-yates/fisher-yates.js" type="module"></script>
2526
<script src="./source/hash-table/linear-hashing/linear-hashing.js" type="module"></script>
26-
<script src="./source/other/sieve-of-eratosthenes.js" type="module"></script>
27+
<script src="./source/other/sieve-of-eratosthenes/sieve-of-eratosthenes.js" type="module"></script>
28+
<script src="./source/other/fibonacchi/fibonacchi.js" type="module"></script>
2729
</body>
2830

2931
</html>

source/other/fibonacchi/fibonacchi.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default function fibonacchi(n) {
2+
if (n == 0) {
3+
return 0;
4+
}
5+
if (n === 1) {
6+
return 0;
7+
}
8+
if (n === 2) {
9+
return 1;
10+
}
11+
let one = 1;
12+
let two = 1;
13+
let result = 0;
14+
for (let i = 3; i <= n; i++) {
15+
result = one + two;
16+
one = two;
17+
two = result;
18+
}
19+
return result;
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getRandomInt, swap } from "../../utils/helpers.js";
2+
3+
export default function fisherYates(array) {
4+
let randomIndex = getRandomInt(0, array.length - 1);
5+
for (var i = 0; i < array.length; i++) {
6+
swap(array, i, randomIndex);
7+
}
8+
return array;
9+
}

0 commit comments

Comments
 (0)