From 1e1996127ed764542711c7f07136e578846aaece Mon Sep 17 00:00:00 2001 From: Cari Date: Sun, 17 Jan 2021 18:13:05 -0500 Subject: [PATCH] finished --- problems/everyOtherLetter.js | 12 ++++++++++-- problems/howManyTargets.js | 10 +++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/problems/everyOtherLetter.js b/problems/everyOtherLetter.js index e6172e1..f4aba03 100644 --- a/problems/everyOtherLetter.js +++ b/problems/everyOtherLetter.js @@ -1,12 +1,20 @@ /** * Returns a new string with every other letter. * @param {string} str - a string - * @returns {str} - + * @returns {str} - * * ex: everyOtherLetter("mississippi") //=> "msispi" * */ -function everyOtherLetter() {} +function everyOtherLetter(str) { + let newStr = ""; + str.split(" ").forEach((i) => { + if (i % 2 === 0) { + newStr += str[i]; + } + }); + return newStr; +} module.exports = everyOtherLetter; diff --git a/problems/howManyTargets.js b/problems/howManyTargets.js index 5843ec5..5e921cb 100644 --- a/problems/howManyTargets.js +++ b/problems/howManyTargets.js @@ -8,6 +8,14 @@ * */ -function howManyTargets() {} +function howManyTargets(array, tar) { + let count = 0; + array.forEach((el) => { + if (el === tar) { + count += 1; + } + }); + return count; +} module.exports = howManyTargets;