From ec5d3f93998fcb056b14b8f3f9c687d892957487 Mon Sep 17 00:00:00 2001 From: VeNoM Date: Sun, 21 Nov 2021 20:31:19 +0530 Subject: [PATCH] Solution of missingLetters that also returns consecutively missed letters --- session3/index_extra.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/session3/index_extra.js b/session3/index_extra.js index 22a94c92..b0dc7642 100644 --- a/session3/index_extra.js +++ b/session3/index_extra.js @@ -113,6 +113,27 @@ function missingLetters(str) { } console.log(missingLetters("abcdefghijklmnopqrstuvwxyz")) +// SOLUTION by VeNoM for missingLetters +// this solution also returns consecutively missed letters +const missingLettersByVeNoM = (str = '') => { + let charCode = str.charCodeAt(0) + let missing = [] + + str.split('').forEach((char) => { + const currCharCode = char.charCodeAt(0) + if (charCode !== currCharCode) { + while (charCode < currCharCode) { + missing.push(String.fromCharCode(charCode)) + charCode++ + } + } + charCode++ + }) + + return missing.join('') +} + +console.log(missingLettersByVeNoM('abcdeghjkn')) // here 'lm' are consecutively missed, so output: film // CHALLENGE 6: EVEN & ODD SUMS // Take in an array and return an array of the sums of even and odd numbers