13 votes

Swift-function which counts the letters, numbers, spaces, special chars in a given string

Returning an array What's your opinion about returning the results in an array? Why would you do that? Because it's an easy way to return the result? Because you don't know how else to do it? How ...
Simon Forsberg's user avatar
7 votes

Swift-function which counts the letters, numbers, spaces, special chars in a given string

Two more ways in addition to Simon's excellent answer: The Char class has convenient methods like isDigit(), isLetter(), etc.: ...
lukas.j's user avatar
  • 244
5 votes

Username Validation RegExp

Your regex looks pretty close to optimal to me, unless I'm missing something. The only adjustments I'd make are: Write some tests if you haven't already (I did ad-hoc tests that can run in the ...
ggorlen's user avatar
  • 3,367
4 votes

Multiple regexp replace in string

Style-wise, it looks odd to see the function argument named in all-caps. Standard convention is to use lower-case (but still upcase it in the doc-string). Trying to run the code, it immediately ...
Toby Speight's user avatar
  • 74.9k
2 votes

Function, which replaces consecutive white-space with a single white-space

A few thoughts: You might consider defining this as a String extension and/or follow standard naming conventions (e.g. removing…...
Rob's user avatar
  • 2,492
2 votes

Matching words from a text with a big list of keywords in Python

The number of the steps that the computer has to do is the length of prescription_text PLUS the length of US_DRUGS PLUS the ...
ma1user1ex's user avatar
2 votes

Convert camelCase and PascalCase to Title Case

Instead of writing and maintaining this function, one could use this publicly available package: to-case. Sample usage: ...
Lydia Stepanek's user avatar
2 votes

Regex to DFA parser in Dart

Just about the built-ins, which it doesn't seem like you are even using, the set equality is terribly expensive, and assumes that the elements are Comparable (so ...
lrn's user avatar
  • 121
1 vote

Convert "String" sqrt(#) into numerical value

It is great that the code uses strict and warnings and has helpful comments. I'll offer some critique on the code and propose an ...
toolic's user avatar
  • 3,031
1 vote

Attempt at Perl transliteration function in JavaScript with flags

5 years later, I too find myself looking for an equivalent for Perl's tr/ operator in JS, only to find the solutions here, but sadly with a severe lack of tests ...
jhm2k's user avatar
  • 21

Only top scored, non community-wiki answers of a minimum length are eligible