Skip to content

Instantly share code, notes, and snippets.

@chalu
Last active August 28, 2023 08:47
Show Gist options
  • Save chalu/dd3d73b41fe70e23901719ff4314425e to your computer and use it in GitHub Desktop.
Save chalu/dd3d73b41fe70e23901719ff4314425e to your computer and use it in GitHub Desktop.
n-fibonacci test

Create a function (e.g nFib) that takes a single integer parameter, n, and returns a list of the first n elements of the Fibonacci sequence.

Example in Javascript:

const nFib = (n) => {
  // TODDO solution begins here
  
  return [];
};

// nFib(1) => [ 0 ]
// nFib(2) => [ 0, 1 ]
// nFib(3) => [ 0, 1, 1 ]
// nFib(4) => [ 0, 1, 1, 2 ]
// nFib(5) => [ 0, 1, 1, 2, 3 ]

Example in Python:

def nFib(n):
    # TODDO solution begins here
    return [];

# nFib(1) => [ 0 ]
# nFib(2) => [ 0, 1 ]
# nFib(3) => [ 0, 1, 1 ]
# nFib(4) => [ 0, 1, 1, 2 ]
# nFib(5) => [ 0, 1, 1, 2, 3 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment