From f2963f1fd38be06968b47c064751857f75e156a1 Mon Sep 17 00:00:00 2001 From: "keith.graves" Date: Tue, 25 Feb 2020 13:44:13 -0600 Subject: [PATCH] Adding one liner solutions with no REGEX. Git Gud --- src/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 17daa32..e3ab9de 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,12 @@ +import moment from 'moment'; /** * CODING CHALLENGE 1 * @param {String} str the string to format * @see `codingChallenge.md` for instructions */ -export function titleCase (str) { - // CODE HERE - return false; +export function titleCase(str) { + return str === null ? (() => { throw new Error('Illegal Argument'); })() : str.split('').map(c => c.toLowerCase()).map(c => (c.charCodeAt(0) > 47 && c.charCodeAt(0) < 58) || (c.charCodeAt(0) > 96 && c.charCodeAt(0) < 123) ? c : ' ').join('').split(' ').map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join(' ').trim(); } /** @@ -14,8 +14,6 @@ export function titleCase (str) { * @param {Number} timestamp the timestamp to format * @see `codingChallenge.md` for instructions */ -export function dateString (timestamp) { - // CODE HERE - return false; +export function dateString(timestamp) { + return timestamp ? new moment(timestamp).format('MMMM DD, YYYY') : timestamp !== null ? new moment().format('MMMM DD, YYYY') : (() => { throw new Error('Illegal Argument'); })(); } -