Skip to content

Instantly share code, notes, and snippets.

@kohlikohl
Last active December 17, 2015 06:58
Show Gist options
  • Save kohlikohl/5568974 to your computer and use it in GitHub Desktop.
Save kohlikohl/5568974 to your computer and use it in GitHub Desktop.
Coding Challenge 4

Coding Challenge 4

This weeks challenge is to write a so called "Pattern Chaser".

Instructions

Language

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.

Judging Criteria

  • 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
  • Execution Time

  • Lines of code

  • Elegance of solution

BONUS!!

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.

Deadline

19:00 - Tuesday 28th May

@tommichaelis
Copy link

What if there are two patterns of the same length - e.g. aa1bb2aa3bb?

@tommichaelis
Copy link

Also, surely if using closure and exposing bnt.patternChaser, we should have goog.provide('bnt'); - check out the array functions in http://docs.closure-library.googlecode.com/git/closure_goog_array_array.js.source.html

@bahulneel
Copy link

Is the number of occurrences ignored in selecting the resultant string? i.e. are we only looking for the longest repeated string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment