Timeline for Turn an integer n into a list containing it n times
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 17, 2020 at 9:15 | review | Low quality posts | |||
Jun 17, 2020 at 14:47 | |||||
Jun 17, 2020 at 9:04 | history | edited | CommunityBot |
Commonmark migration
|
|
Aug 21, 2017 at 14:53 | review | Low quality posts | |||
Aug 21, 2017 at 14:58 | |||||
Aug 21, 2017 at 14:52 | comment | added | AnonymousReality |
Didn't realise you didn't need the Array there and interesting how the _ in n works, would never have thought of that. However, the challenge says to "return a list", which to me would suggest you need to return something, not just print it, but that may just be my interpretation. I've updated with the other suggestions though, thanks!
|
|
Aug 21, 2017 at 14:51 | history | edited | AnonymousReality | CC BY-SA 3.0 |
Optimised thanks to Mr. xcoder
|
Aug 21, 2017 at 12:52 | comment | added | Mr. Xcoder |
$0+n-$0 can be replaced by _ in n for -1 bytes. Additionally, you can print rather than return and ->[Int] to save tons of bytes. You can also remove Array and the space before it. This ends up being 41 bytes: func a(n:Int){print((0..<n).map{_ in n})}
|
|
Aug 21, 2017 at 12:43 | review | Low quality posts | |||
Aug 21, 2017 at 12:48 | |||||
Aug 21, 2017 at 12:26 | history | answered | AnonymousReality | CC BY-SA 3.0 |