Lodash TakeRight Lab

Medium
6
2
31.3% Acceptance

In this lab, you will practice using the Lodash _.takeRight() function. This function allows you to slice an array by taking a specified number of elements from the end of the array. It returns a new array containing the extracted elements.

The syntax for the _.takeRight() function is as follows:

_.takeRight(array, [n=1])

Where array is the input array and n is the number of elements to take from the end (default value is 1).

In this lab, you will create a helper function getTopScores(scores, n) that receives an array of test scores and returns the top 'n' scores using the Lodash _.takeRight() function. You will also create unit tests for the helper function and run them using Jest.

Challenges

  1. Export the getTopScores(scores, n) function
  2. Implement the getTopScores(scores, n) function using _.takeRight
  3. Create and export an array of test cases for getTopScores()
  4. Create a Jest test file for testing getTopScores()

Learn more about Lodash _.takeRight() function in its official documentation.