DEV Community

loading...

Discussion on: Daily Challenge #172 - Find All in an Array

Collapse
ryanbeckett profile image
Ryan Beckett

Swift:

func findOccurances(of numberToFind: Int, in listOfNumbers: [Int]) -> [Int] {
    return listOfNumbers.enumerated().compactMap { (index, number) in
        number == numberToFind ? index : nil
    }
}