Skip to content

Instantly share code, notes, and snippets.

@proustibat
Created January 2, 2016 23:37
Show Gist options
  • Save proustibat/56bb6eeed4a33dff8d08 to your computer and use it in GitHub Desktop.
Save proustibat/56bb6eeed4a33dff8d08 to your computer and use it in GitHub Desktop.
function happyNewYear(wish) {
var _arr = wish.match(/\S+\s*/g);
var _startStr = "* ",
_endStr = "*",
_longestLength = wish.match(/\S+\s*/g).sort(function (a, b) { return b.length - a.length; })[0].length,
_lengthToGet = _longestLength + _startStr.length + _endStr.length,
_ref = Array(_lengthToGet).join("*") + _endStr,
_result = [];
for (var i=0, l=_arr.length; i<l; i++) {
_result.push( _startStr + _arr[i].replace(" ", "") + Array(_lengthToGet - _arr[i].replace(" ", "").length - _startStr.length).join(" ") + _endStr );
}
_result.unshift(_ref);
_result.push(_ref);
console.log(_result);
return _result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment