JS
challenger
JS
challenger
  • Getting Started
  • Overview
  • Random Challenge
  • Javascript Basics
  • Javascript Arrays
    • - Get nth element of array
    • - Remove first n elements of an array
    • - Get last n elements of an array
    • - Get first n elements of an array
    • - Return last n array elements
    • - Remove a specific array element
    • - Count number of elements in JavaScript array
    • - Count number of negative values in array
    • - Sort an array of numbers in descending order
    • - Sort an array of strings alphabetically
    • - Return the average of an array of numbers
    • - Return the longest string from an array of strings
    • - Check if all array elements are equal
    • - Merge an arbitrary number of arrays
    • - Sort array by object property
    • - Merge two arrays with duplicate values
    • - Sum up all array elements with values greater than
    • - Create a range of numbers
    • - Group array of strings by first letter
    • - Define an array with conditional elements
    • - Get every nth element of array
  • Javascript Objects
  • Javascript Dates
  • Javascript Sets
  • Javascript DOM
    NEW
  • Challenge Rush
Imprint Privacy Policy

Get last n elements of an array

// Write a function that takes an array (a) as argument
// Extract the last 3 elements of a
// Return the resulting array
function
myFunction
(
a
)
{

return
}
Test Cases:
myFunction([1,2,3,4])
Expected
[2,3,4]
myFunction([5,4,3,2,1,0])
Expected
[2,1,0]
myFunction([99,1,1])
Expected
[99,1,1]
Twitter_Logo_White-on-Blue
Follow