-
-
Save vibinnair/e75a803f7d9dd1dd29e3a46ea27d9d51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.hackerrank.com/challenges/fp-filter-array/problem | |
import Foundation | |
func filterList(_ upperLimit: Int, _ list: [Int]) -> [Int] { | |
if list.count <= 0 { | |
return [] | |
} | |
let element = list.first! | |
let newList = Array(list.dropFirst(1)) | |
if element < upperLimit { | |
return [element] + filterList(upperLimit, newList) | |
} | |
return filterList(upperLimit, newList) | |
} | |
print(filterList(3, [1, 2, 3, 4])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment