Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
It doesn't work for me due to 12s timeout.
Your solution is O(N^2). There exists a formula that can help you solve the problem with just O(N) time complexity. (1-time iteration)
A positive integer is an integer greater than 0.
But if you want to be sure, then yes you could validate the input too. Not needed here tho.
If anyone accidentally calls divisors(0) then this will crash. There needs to be a check like:
guard n != 0 else { return 0 }
However I'm not sure what you should return. Returning 0 would technically be right. 0 has 0 divisors since 0 can't be divided.
This is not a best practice. If you are testing the number 1000, you are applying
n % $0 == 0
499 times more than needed.This was too difficult to be 5 kyu.
should've been above 3
I hate this kata, but was a good practice
I'm so sad to find out .maxReplacements cannot be used in Swift
due to old API maybe?
This comment is hidden because it contains spoiler information about the solution