Skip to content

Instantly share code, notes, and snippets.

@IsTheJack
Last active August 30, 2018 13:01
Show Gist options
  • Save IsTheJack/d8fdbd31e6fb7fc0af3db24017fcd243 to your computer and use it in GitHub Desktop.
Save IsTheJack/d8fdbd31e6fb7fc0af3db24017fcd243 to your computer and use it in GitHub Desktop.
A função 'getLast' retorna o último elemento de uma array sem causar nenhuma exceção ou qualquer tipo de warning. Qual melhoria você faria nessa função. Por que?
/**
* Get the last element of an array
* @function getLast
* @argument {Array} arr
* @returns
*/
const getLast = arr => arr.pop()
const numbers = [1, 2, 3, 4, 5]
console.log(getLast(numbers)) // => 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment