From 5ab876bc9fc282a9fd9d4f4a4687204201f32a89 Mon Sep 17 00:00:00 2001 From: Lance Hammond Jr Date: Mon, 10 Aug 2020 00:26:48 -0500 Subject: [PATCH] Day 1 Node/NPM --- src/dates/index.js | 36 +++++++++++++++++++++++++++++++++--- src/numbers/index.js | 18 +++++++++++++++--- src/strings/index.js | 13 ++++++++++--- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/dates/index.js b/src/dates/index.js index 91cdc8e..e9ee90e 100644 --- a/src/dates/index.js +++ b/src/dates/index.js @@ -1,20 +1,50 @@ // import moment here; use this package in each function +var moment = require('moment'); + const today = () => { // write code for dates.today - + const d = new Date().getDay() + if (d == 0) { + return 'Sunday' + } + else if (d == 1) { + return 'Monday' + } + else if (d == 2) { + return 'Tuesday' + } + else if (d == 3) { + return 'Wednesday' + } + else if (d == 4) { + return 'Thursday' + } + else if (d == 5) { + return 'Friday' + } + else { + return 'Saturday' + } } +//today() + const calendar = () => { // write code for dates.calendar - + return moment().format('MMM DD, YYYY'); + } +//calendar() const currentTime = () => { // write code for dates.currentTime - + return moment().format('hh:mm:ss A'); + } +//currentTime() + module.exports = { today, calendar, diff --git a/src/numbers/index.js b/src/numbers/index.js index 014b8ca..7fe26db 100644 --- a/src/numbers/index.js +++ b/src/numbers/index.js @@ -1,16 +1,28 @@ const isEven = (num) => { // write code for numbers.isEven - + if (num % 2 === 0) { + return true; + } } const sum = (arr) => { // write code for numbers.sum - + let s = 0; + for (let i = 0; i < arr.length; i++) { + s += arr[i]; + } + return s; } const comboSum = (arr, sum) => { // write code for numbers.comboSum - + let reducer = (accumulator, currentValue) => accumulator + currentValue; + let t = arr.reduce(reducer); + if(t == sum){ + return true; + } else { + return false; + } } module.exports = { diff --git a/src/strings/index.js b/src/strings/index.js index eee93b9..d7dfe85 100644 --- a/src/strings/index.js +++ b/src/strings/index.js @@ -1,16 +1,23 @@ const split = (str, delim) => { // write code for strings.split - + return str.split(delim) } const pairs = (str) => { // write code for strings.pairs - + let x = [] + for(let i= 0; i < str.length-1; i++) { + if(i%2 ===0) { + x.push(`${str[i]}${str[i+1]}`) + } + } + return x } const reverse = (str) => { // write code for strings.reverse - + let y = str.split('').reverse().join('') + return y; } module.exports = {