Sure thing! This is the Ternary Operator, it's basically a single line if condition. The question mark asks whatever is on it's left if it's true or false. It then tells the colon to pick whatever is to it's left if the condition is true, or to it's right if the condition is false
Great solution. However, you can still be more expressive than this in Swift. Like: !"abcdefghijklmnopqrstuvwxyz".lazy.map(string.lowercased().contains).contains(false)
And it should be a bit faster, because you don't need to iterate over the whole input, just all the letters in the alphabet. And thanks to lazy, it should stop the first time it gets false.
Functions With an Implicit Return
search here - https://docs.swift.org/swift-book/LanguageGuide/Functions.html
Where "return"? How it work?
Random tests almost never generate pangrams.
Almost all tests can be passed with
return false
as a solution.Implemented it
Oh, that's a great use of lazy! Thanks for the suggestion, will apply it to the solution :)
No random tests.
Approved
Thank you so much brother
Sure thing! This is the Ternary Operator, it's basically a single line if condition. The question mark asks whatever is on it's left if it's true or false. It then tells the colon to pick whatever is to it's left if the condition is true, or to it's right if the condition is false
You should take a look at the official Swift documentation https://docs.swift.org/swift-book/LanguageGuide/BasicOperators.html. You can search for Ternary and you'll find whatever you're looking for
hey could someone explain this code to me please
Great solution. However, you can still be more expressive than this in Swift. Like:
!"abcdefghijklmnopqrstuvwxyz".lazy.map(string.lowercased().contains).contains(false)
And it should be a bit faster, because you don't need to iterate over the whole input, just all the letters in the alphabet. And thanks to
lazy
, it should stop the first time it gets false.Lovely <3 gg wp
Approved
Maybe change the function to
func findUniq<N: Numeric>(_ arr: [N]) -> N {
Yep, this is mostly a math challenge
Loading more items...