Skip to content

Instantly share code, notes, and snippets.

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!
https://www.hackerrank.com/challenges/fp-filter-positions-in-a-list/problem
import Foundation
func filterOddElements(_ list: [Int]) -> [Int] {
if list.count <= 1 {
return []
}
let elements = list.prefix(2)
@vibinnair
vibinnair / gist:51e95bdbe180af2d07f3ceca522250d7
Created August 5, 2019 07:51
Functional Swift: Retreive all hashtags from a string
//Ref: https://www.swiftbysundell.com/basics/map-flatmap-and-compactmap
import Foundation
func hashTags(from string: String) -> [String] {
return string.components(separatedBy: .whitespacesAndNewlines)
.filter {string in string.starts(with: "#")}
}
print(hashTags(from: "#WWDC 2019 was #awesome #greatday"))