So, the challenge is that we are trying to detect if a string matches a fixed phone number pattern, this is a simple string pattern.
The pattern is:
very fast:
function tecjam3(pattern) {
if (pattern.length !== 12) {
return false;
}
code = pattern.charCodeAt(0);
if (code < 48 || code > 57) return false;
code = pattern.charCodeAt(1);
if (code < 48 || code > 57) return false;
code = pattern.charCodeAt(2);
if (code < 48 || code > 57) return false;
code = pattern.charCodeAt(4);
if (code < 48 || code > 57) return false;
code = pattern.charCodeAt(5);
if (code < 48 || code > 57) return false;
code = pattern.charCodeAt(6);
if (code < 48 || code > 57) return false;
code = pattern.charCodeAt(8);
if (code < 48 || code > 57) return false;
code = pattern.charCodeAt(9);
if (code < 48 || code > 57) return false;
code = pattern.charCodeAt(10);
if (code < 48 || code > 57) return false;
code = pattern.charCodeAt(11);
if (code < 48 || code > 57) return false;
if (pattern.charAt(3) != '-' || pattern.charAt(7) != '-') return false;
return true;
}