Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dateString.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';
import moment from 'moment';
import { dateString } from './index';

if (dateString()) {
if (dateString('d') != null) {
test('Nominal', t => {
const actual = 1485470818000;
const expected = 'January 26, 2017';
Expand Down
39 changes: 33 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@

import moment from "moment";
/**
* CODING CHALLENGE 1
* @param {String} str the string to format
* @see `codingChallenge.md` for instructions
*/
export function titleCase (str) {
export function titleCase(str) {
// CODE HERE
return false;
try {
if (str != null) {
const strReplace = str.replace(/[^a-zA-Z0-9]+/g, " ");
const lowCase = strReplace.toLowerCase().trim();
const splitWords = lowCase.split(" ");

for (let i = 0; i < splitWords.length; i++) {
splitWords[i] =
splitWords[i][0].toUpperCase() + splitWords[i].substr(1);
}

return splitWords.join(" ");
}
} catch (error) {
throw new Error("Null Input");
}
}

/**
* CODING CHALLENGE 2
* @param {Number} timestamp the timestamp to format
* @see `codingChallenge.md` for instructions
*/
export function dateString (timestamp) {
export function dateString(timestamp) {
// CODE HERE
return false;
}

try {
if (!timestamp && !null) {
const today = new moment().format("MMMM D, YYYY");
return today;
} else if (timestamp != null) {
const toDate = new Date(timestamp);
let formattedDate = moment(toDate).format("MMMM D, YYYY");

return formattedDate;
}
} catch (error) {
throw new Error("Null Input");
}
}