mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-11-09 22:08:58 +01:00
✨ Add "fibonacci-suite" challenge
This commit is contained in:
parent
e1eb4f73ea
commit
59e0d5934d
12
challenges/fibonacci-suite/README.md
Normal file
12
challenges/fibonacci-suite/README.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# fibonacci-suite
|
||||||
|
|
||||||
|
Created by [@Divlo](https://github.com/Divlo) at 5 July 2020.
|
||||||
|
|
||||||
|
## Instructions :
|
||||||
|
|
||||||
|
The function should return an array of fibonacci numbers. The function takes a `number` as an argument to decide how many number of elements to produce.
|
||||||
|
**Note :** The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Each subsequent number is the sum of the previous two.
|
||||||
|
|
||||||
|
## Examples :
|
||||||
|
|
||||||
|
See the `input-output.json` file for examples of input/output.
|
6
challenges/fibonacci-suite/input-output.json
Normal file
6
challenges/fibonacci-suite/input-output.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"input": [14],
|
||||||
|
"output": [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]
|
||||||
|
}
|
||||||
|
]
|
0
challenges/fibonacci-suite/solutions/.gitkeep
Normal file
0
challenges/fibonacci-suite/solutions/.gitkeep
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# typescript-recursive - fibonacci-suite
|
||||||
|
|
||||||
|
Programming language : TypeScript
|
||||||
|
Created by [@Divlo](https://github.com/Divlo) at 5 July 2020.
|
@ -0,0 +1,8 @@
|
|||||||
|
function solution (counter: number, result: number[] = [], number1: number = 0, number2: number = 1): number[] {
|
||||||
|
if (counter === 0) return result
|
||||||
|
counter--
|
||||||
|
result.push(number1)
|
||||||
|
return solution(counter, result, number2, number1 + number2)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default solution
|
Loading…
Reference in New Issue
Block a user