Retornar o último item

Published by 2535m in

Retorne o último item de um array, ou o caractere final de uma string. Para uma entrada vazia, retorne undefined.

Exemplos

lastItem([0, 4, 19, 34, 50, -9, 2]) ➞ 2

lastItem("The quick brown fox jumped over the lazy dog") ➞ "g"

lastItem([]) ➞ undefined

Observações

  • Arrays e strings terão tamanhos variados.
  • Retorne undefined se o array ou a string estiverem vazios.