From 6cdc9005539063db5695bf3991b31830d39dc427 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Tue, 2 Jun 2020 14:36:08 -0500 Subject: [PATCH] finished node practice --- src/dates/index.js | 7 ++++--- src/numbers/index.js | 19 +++++++++++++------ src/strings/index.js | 12 +++++++++--- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/dates/index.js b/src/dates/index.js index 91cdc8e..e56b074 100644 --- a/src/dates/index.js +++ b/src/dates/index.js @@ -1,18 +1,19 @@ // import moment here; use this package in each function - +const moment = require ("moment") const today = () => { // write code for dates.today + return moment().format("dddd") } const calendar = () => { // write code for dates.calendar - + return moment().format("MMM DD, YYYY") } const currentTime = () => { // write code for dates.currentTime - + return moment().format("hh:mm:ss A") } module.exports = { diff --git a/src/numbers/index.js b/src/numbers/index.js index 014b8ca..d499e6a 100644 --- a/src/numbers/index.js +++ b/src/numbers/index.js @@ -1,18 +1,25 @@ const isEven = (num) => { // write code for numbers.isEven - -} + if (num % 2 === 0) { + } return true; + } const sum = (arr) => { // write code for numbers.sum - + return arr.reduce((a, b) => a + b, 0); } const comboSum = (arr, sum) => { // write code for numbers.comboSum - -} - + let arrSum = arr.reduce(function (a, b) { return a + b + }, 0); + if (arrSum === sum) { + return true + } else { + return false + } + } + module.exports = { isEven, sum, diff --git a/src/strings/index.js b/src/strings/index.js index eee93b9..102d949 100644 --- a/src/strings/index.js +++ b/src/strings/index.js @@ -1,16 +1,22 @@ const split = (str, delim) => { // write code for strings.split - + return str.split(delim) } const pairs = (str) => { // write code for strings.pairs - + let strList = [] + for(let i= 0; i < str.length-1; i++) { + if(i%2 ===0) { + strList.push(`${str[i]}${str[i+1]}`) + } + } + return strList } const reverse = (str) => { // write code for strings.reverse - + return str.split("").reverse().join("") } module.exports = {