Silver Challenge

Write a generic function called findAll(_:_:) that takes an array of any type T that conforms to the Equatable protocol and a single element (also of type T). findAll(_:_:) should return an array of integers corresponding to every location where the element was found in the array. For example, findAll([5,3,7,3,9], 3) should return [1,3] because the item 3 exists at indices 1 and 3 in the array. Try your function with both integers and strings.

Get Swift Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.