Похожие чаты

Ohh here's a fun one... Challenge to you: make this

smaller without just making vars 1 letter.

const acc = arr.length > 0 ? arr.length - 1 : 0;

Usable to get last element of array

4 ответов

14 просмотров

you can delete > 0

arr[-1] will just return undefined as well, so why not just: const acc = arr.length - 1;

arr.length || 1 - 1

Dani- Автор вопроса

Look at this closely, for 1 element in array you assume index 0... No checking for undefined later. If there is more than one you assume length - 1

Похожие вопросы

Обсуждают сегодня

Карта сайта