From 44ed6bf874fd0607afe470a195c3f52becd31453 Mon Sep 17 00:00:00 2001 From: DavidCastillo4 Date: Thu, 6 Aug 2020 11:37:12 -0500 Subject: [PATCH] completed project --- src/dates/index.js | 19 ++++++++++--------- src/numbers/index.js | 21 ++++++++++++--------- src/strings/index.js | 23 +++++++++++++++-------- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/dates/index.js b/src/dates/index.js index 91cdc8e..bbfe411 100644 --- a/src/dates/index.js +++ b/src/dates/index.js @@ -1,22 +1,23 @@ // import moment here; use this package in each function +var moment = require('moment'); const today = () => { - // write code for dates.today - + // write code for dates.today + return moment().format('dddd'); } const calendar = () => { - // write code for dates.calendar - + // write code for dates.calendar + return moment().format('MMM d, YYYY'); } const currentTime = () => { - // write code for dates.currentTime - + // write code for dates.currentTime + return moment().format('h:mm:ss A'); } module.exports = { - today, - calendar, - currentTime + today, + calendar, + currentTime } \ No newline at end of file diff --git a/src/numbers/index.js b/src/numbers/index.js index 014b8ca..aa808e3 100644 --- a/src/numbers/index.js +++ b/src/numbers/index.js @@ -1,20 +1,23 @@ const isEven = (num) => { - // write code for numbers.isEven - + // write code for numbers.isEven + return (num % 2 ? false : true); } const sum = (arr) => { - // write code for numbers.sum - + // write code for numbers.sum + let n = arr.reduce((acc, cur) => (acc + cur)) + return n; } const comboSum = (arr, sum) => { - // write code for numbers.comboSum - + // write code for numbers.comboSum + let n = 0; + arr.forEach(e => { n += e }); + return (n == sum ? true : false); } module.exports = { - isEven, - sum, - comboSum + isEven, + sum, + comboSum } \ No newline at end of file diff --git a/src/strings/index.js b/src/strings/index.js index eee93b9..5180933 100644 --- a/src/strings/index.js +++ b/src/strings/index.js @@ -1,20 +1,27 @@ const split = (str, delim) => { - // write code for strings.split + // write code for strings.split + return str.split(delim); } const pairs = (str) => { - // write code for strings.pairs - + // write code for strings.pairs + let arr = []; + for (let i = 0; i < str.length; i += 2) { + let a = str[i] + str[i + 1]; + arr.push(a); + } + return arr; } const reverse = (str) => { - // write code for strings.reverse - + // write code for strings.reverse + return str.split("").reverse().join(""); } + module.exports = { - split, - pairs, - reverse + split, + pairs, + reverse } \ No newline at end of file