Lodash TakeRight Lab
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:
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.
- Export the getTopScores(scores, n) function
- Implement the getTopScores(scores, n) function using _.takeRight
- Create and export an array of test cases for getTopScores()
- Create a Jest test file for testing getTopScores()
Learn more about Lodash
_.takeRight() function in its official documentation.