Update head.md

This commit is contained in:
Angelos Chalaris
2019-12-11 09:52:00 +02:00
committed by GitHub
parent ec28d5fa6f
commit 980499db57

View File

@ -5,8 +5,7 @@ tags: array,beginner
Returns the head of a list.
Check if `arr` is truthy and has a `length` property, use `arr[0]` if possible
to return the first element, otherwise return `undefined`
Check if `arr` is truthy and has a `length` property, use `arr[0]` if possible to return the first element, otherwise return `undefined`.
```js
const head = arr => (arr && arr.length ? arr[0] : undefined);