Optimization of last element selection

arr[arr.lenght - 1] ==> arr.slice(-1)[0]