hongbo-miao/hongbomiao.com

View on GitHub
api-node/src/graphQL/utils/getFibonacci.ts

Summary

Maintainability
A
0 mins
Test Coverage
import validator from 'validator';
import calcFibonacci from './calcFibonacci';

type Fibonacci = {
  n: number;
  ans: number;
};

const getFibonacci = (n: number): Fibonacci => {
  if (!validator.isInt(String(n), { min: 0, max: 20 })) {
    throw new Error('n should be in the range of 0 and 20.');
  }
  return {
    n,
    ans: calcFibonacci(n),
  };
};

export default getFibonacci;