Use findIndex and pattern-matching to find the index of an elememt