by spamizbad · 8y ago · 0 comments
"Write a function that counts the number of vowels in a string"
Candidates are allowed to run it multiple times and just have to produce a correct result within 10 minutes. It's not a trick question -- the test case in place makes sure you pay attention to case.
Success rate for mid to senior devs? Only 60%.
"Write a function that reverses the words in a (string) sentence"
i.e. (x) => x.split(' ').reverse().join(' ');
The fastest way to reverse a string is in JS is:
function reverse(s) {
var o = [];
for (var i = 0, len = s.length; i <= len; i++)
o.push(s.charAt(len - i));
return o.join('');
} return inputString.Count( "eaoiuAIEOU".Contains );
Or if you want to solve two problems: static Regex VowelMatcher = new Regex( "[aeiou]",
RegexOptions.Compiled | RegexOptions.IgnoreCase );
...
return VowelMatcher.Matches( inputString ).Count;
And if you want to be clever and snarky: return 2; // number of vowels in "a string"Took me less than 10 seconds to come up with an approach that would work oh just though of a more efficient one but that would use a regex :-)