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;