This file contains hidden or 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! |
This file contains hidden or 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-positions-in-a-list/problem | |
import Foundation | |
func filterOddElements(_ list: [Int]) -> [Int] { | |
if list.count <= 1 { | |
return [] | |
} | |
let elements = list.prefix(2) |
This file contains hidden or 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
//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")) |
OlderNewer