Fibonacci
介绍
实现斐波那契序列. 接收数值T, 返回它相关的斐波那契数列(https://en.wikipedia.org/wiki/Fibonacci_number).
序列: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
ts
type Fibonacci<T extends number> = anytype Result1 = Fibonacci<3> // 2type Result2 = Fibonacci<8> // 21
View on GitHubts
type Fibonacci<T extends number> = anytype Result1 = Fibonacci<3> // 2type Result2 = Fibonacci<8> // 21
起点
ts
/* _____________ Your Code Here _____________ */typeFibonacci <T extends number> = any/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Fibonacci <1>, 1>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Fibonacci <2>, 1>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Fibonacci <3>, 2>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Fibonacci <8>, 21>>,]
take the challengets
/* _____________ Your Code Here _____________ */typeFibonacci <T extends number> = any/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Fibonacci <1>, 1>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Fibonacci <2>, 1>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Fibonacci <3>, 2>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Fibonacci <8>, 21>>,]
解决方案
Spoiler warning // Click to reveal answer
ts
// most populartypeFibonacci <T extends number> = any
ts
// most populartypeFibonacci <T extends number> = any