3 ms·
String reversal at least involves a backwards loop, which isn't that hard, but you don't use often in practice. I'd guess there are 10x as many for-of loops as
by hyperpape 11y ago
String reversal at least involves a backwards loop, which isn't that hard, but you don't use often in practice. I'd guess there are 10x as many for-of loops as for i = 0...loops in our codebase, and 10x as many for i = 0...loops as backwards loops in our code base. I think Swift may be removing C-style for loops, even (https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001978.html https://lists.swift.org/pipermail/swift-evolution/Week-of-Mo...). Of course you can still express it using a while-loop, but this reflects the frequency of certain types of code.
On the one hand, I'm tempted to say everyone should be able to do that, on the other hand, they do feel like a type of programming that isn't super common in a lot of applications. FizzBuzz is probably a bit better in that regard.
- distances 11y agoNot necessarily a backwards loop, it can be done just fine with a simple recursion too. If a candidate can't do either, well, this is a task explicitly to weed out those candidates.