Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion
Fibonacci numbers
FacileBasics10 min
Write a function fibonacci(n) that returns an array with the first n Fibonacci numbers.
- The sequence starts with
0and1. Every next number is the sum of the two numbers before it:0, 1, 1, 2, 3, 5, 8, 13, ... - The parameter
nis an integer from 0 to 50. For0return an empty array[].
Then write a second function fibonacciBetween(min, max). It returns every Fibonacci number x with min <= x <= max, in the order of the sequence.
1is in the sequence twice, keep both:fibonacciBetween(1, 1)returns[1, 1].- If no number fits, return
[]. minandmaxare integers,0 <= min <= max <= 1000000.
Exemples
fibonacci(7)Renvoie [ 0, 1, 1, 2, 3, 5, 8 ]
fibonacci(1)Renvoie [ 0 ]
fibonacciBetween(50, 100)Renvoie [ 55, 89 ]
Posé chez Accion Labs · Source
Chargement de l'éditeur...
- Entrée
fibonacci(7)Attendu[ 0, 1, 1, 2, 3, 5, 8 ] - Entrée
fibonacci(1)Attendu[ 0 ] - fibonacciBetween(50, 100) returns [55, 89]
- Entrée
fibonacci(0)Attendu[]
Les tests cachés se lancent à la soumission