This weeks challenge is to write a so called "Pattern Chaser".
JavaScript
Expose a function called bnt.patternChaser(str)
to the global namespace which takes one string
as a parameter and returns "yes [found pattern]"
or "no null"
.
The found pattern should be the longest pattern which can be found in the string.
A pattern for this challenge will be defined as:
- If at least 2 or more adjacent characters within the string repeat at least twice. So for example
"aabecaa"
contains the pattern"aa"
, on the other hand"abbbaac"
doesn't contain any pattern. - If str were
"aabejiabkfabed"
the output should be"yes abe"
. - If str were
"123224"
the output should return"no null"
. - The string may either contain all characters (a through z only), integers, or both. But the parameter will always be a string type.
- The maximum length for the string being passed in will be 20 characters.
- If a string for example is
"aa2bbbaacbbb"
the pattern is"bbb"
and not"aa"
. You must always return the longest pattern possible.
-
Coding Style:
- Does the code lint in JSLint with following settings:
/*jslint browser: true, plusplus: true, sloppy: true, stupid: false, indent: 4 */
- Use of language features
- Does the code lint in JSLint with following settings:
-
Execution Time
-
Lines of code
-
Elegance of solution
Use the Google Closure Library.
If you choose to use the library please create the module in the goog.provide('bnt.PatternChaser');
namespace and make sure it still exposes the bnt.patternChaser(str)
function.
19:00 - Tuesday 28th May
Is the number of occurrences ignored in selecting the resultant string? i.e. are we only looking for the longest repeated string?