News for hackers. Stuff that matters.
Re:Code Wars (JS, Coffeescript & Ruby) by mattezell on Tuesday July 02, 2013 @02:56PM (#5979975)
Yea.. Can't get this to work..

Q: Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length0).

My Answer:

  function solution(a, b){
    if(typeof(undefined) == typeof(a))
      a = "";
    if(typeof(undefined) == typeof(b))
      b = "";

    if(a.length > b.length)
      return b + a + b;
    else
      return a + b + a;
  }
Result: "Unknown Error"

Of course my solution doesn't account for a.length == b.length, but the question is somewhat nonsensical in that it states '...strings will not be the same length, but they may be empty...' (2 empty strings would be the same length)...

There are no comments on this comment yet.