Skip to content

Latest commit

 

History

History
8 lines (7 loc) · 352 Bytes

File metadata and controls

8 lines (7 loc) · 352 Bytes

Given a list of integers, swap the first and last elements in the list. Return the modified list. The list will always have at least one element.

For example:

  • swapEnds([1, 2, 3, 4]) → [4, 2, 3, 1]
  • swapEnds([1, 2, 3]) → [3, 2, 1]
  • swapEnds([8, 6, 7, 9, 5]) → [5, 6, 7, 9, 8]
  • swapEnds([10]) → [10]
  • swapEnds([2, 4]) → [4, 2]