smaller without just making vars 1 letter.
const acc = arr.length > 0 ? arr.length - 1 : 0;
Usable to get last element of array
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
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
Обсуждают сегодня