News for hackers. Stuff that matters.
Re:Interviewing a front-end developer by club7g on Thursday January 30, 2014 @05:06AM (#7149851)
I don't mean to be pedantic; well actually I do. The spacify solution is incorrect as the sample suggests that a blank space is not replaced with 2 blank spaces.

A correct solution would be:

function spacify(input) { return input.replace(/([^ ])/g, '$1 '); }

Re:Interviewing a front-end developer by himal on Thursday January 30, 2014 @05:23AM (#7149918)
Actually, there are two spaces in the given example output as well.

Additionally, you could also use,

  function spacify(str) {
  return str.split('').join(' ').replace('  ','');
  }
to remove the additional space.
Re:Interviewing a front-end developer by club7g on Thursday January 30, 2014 @05:41AM (#7149963)
Yep 2 spaces was the intention, where as the original implementation yields 3 spaces. My codes failure is that it appends a blank space to the end... I guess the real take away here is that there are many ways to achieve the same outcome. Knowledge of quirks is not essential. I would think the most important first step is understanding the requirements, what sort of performance is acceptable given the intended usage, coding for maintainability and ease of usage. For example, the solution for ensuring getCount has the proper context requires knowing how getCount was implemented then taking extra steps. A better solution may be something like this: var User = { count : 1 }; User.getCount = function() { return User.count; }
Re:Interviewing a front-end developer by thomasfromcdnjs on Thursday January 30, 2014 @08:09AM (#7150422)
I would have done

var spacify = function (s) { return s.match(/\w/g).join(' ') };