Created
January 2, 2016 23:37
-
-
Save proustibat/56bb6eeed4a33dff8d08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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