Find nil in an Array

Published by Matt in

Create a function to find nil in an array of numbers. The return value should be the index where nil is found. If nil is not found in the array, return -1.

Examples

find_nil([1, 2, nil]) ➞ 2

find_nil([nil, 1, 2, 3, 4]) ➞ 0

find_nil([0, 1, 2, 3, 4]) ➞ -1

Notes

nil will occur in the input array only once.

Watch a quick demo on how Edabit works.