greena13/react-hotkeys

View on GitHub
src/utils/array/indexFromEnd.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * Returns the element in an array at a particular index from the end
 * @param {Array.<T>} array Array to iterate over to find the item
 * @param {number} placesFromEnd Number of places from the end of the array to find
 *        the item to return
 * @returns {T} The item found in the array at the particular index
 * @template T
 */
function indexFromEnd(array, placesFromEnd) {
  return array[array.length - (placesFromEnd + 1)];
}

export default indexFromEnd;