From bcf20ca95155f2e1b7019cbbf4397e8b3c7f6cb9 Mon Sep 17 00:00:00 2001 From: Damilola Adegoke Date: Tue, 31 Jan 2023 15:59:56 +0100 Subject: [PATCH 1/4] Problem Solved --- src/isolate-duplicates/index.js | 30 +++++++++++++++++++++++++++++- src/morse/index.js | 16 +++++++++++++++- src/remove-dulplicates/index.js | 15 ++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/isolate-duplicates/index.js b/src/isolate-duplicates/index.js index 79ae426..4eba81f 100644 --- a/src/isolate-duplicates/index.js +++ b/src/isolate-duplicates/index.js @@ -1,3 +1,31 @@ -function isolateDuplicates(text) {} +function isolateDuplicates(text) { + function isolateDuplicates(text) { + + if (typeof text !== 'string') { + throw new Error('Please enter a valid string') + } + + let lowerText = text.toLowerCase() + + let newString = "" + let count = 0 + + for (let i = 0; i < text.length; i++) { + newString += text[i] + + if (lowerText[i] === lowerText[i - 1] && lowerText[i] === lowerText[i + 1] && lowerText[i] !== lowerText[i - 2]) { + newString += '[' + count++ + } + + if (lowerText[i] === lowerText[i - 1] && lowerText[i] !== lowerText[i + 1] && lowerText[i] === lowerText[i - 2] ) { + newString += ']' + } + } + return [newString, count] + } + + console.log(isolateDuplicates("aaAabbcdefffffffg")) +} module.exports = isolateDuplicates; diff --git a/src/morse/index.js b/src/morse/index.js index cf65063..faae9d1 100644 --- a/src/morse/index.js +++ b/src/morse/index.js @@ -58,6 +58,20 @@ const MORSE_CODE = { Object.freeze(MORSE_CODE); -function morse(text) {} +function morse(text) { + let _morseArr = text.trim().split(" "); + let _arrOfDecodedWords = _morseArr.map((item) => { + let getMorseCodeFromItem = item.split(" "); + let getWordsFromItemArray = getMorseCodeFromItem.map((value) => { + + let decodedLetter = MORSE_CODE[VALUE]; + return decodedLetter; + }) + return getWordsFromItemArray.join("") + }) + return _arrOfDecodedWords.join (" "); +} + +console.log(morse(",-")) module.exports = morse; diff --git a/src/remove-dulplicates/index.js b/src/remove-dulplicates/index.js index 75c6c9b..80ff06d 100644 --- a/src/remove-dulplicates/index.js +++ b/src/remove-dulplicates/index.js @@ -1,3 +1,16 @@ -function removeDuplicates(obj) {} +function removeDuplicates(obj) { + function removeDuplicates(obj) { + let n = []; + + let rep = (a, b) => [...new Set([...a].filter( x => !b.includes(x)))]; + + return Object.entries(obj).reverse().map(element => { + const aux = n; + n = [...new Set([...n, ...element[1]])]; + + return [element[0], [...new Set(rep(element[1], aux))]]; + }).reduce((arrays, array) => ((arrays[array[0]] = array[1]), arrays), {}); + } +} module.exports = removeDuplicates; From c026195cfb6e327e81422e04def1f56fa769e8f5 Mon Sep 17 00:00:00 2001 From: Damilola Adegoke Date: Tue, 31 Jan 2023 16:15:32 +0100 Subject: [PATCH 2/4] Solution done --- .DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 8196 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store create mode 100644 src/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9c0ea4ede72f227a1592bcc7cccafa45d2fb76f3 GIT binary patch literal 6148 zcmeHK&5qMB5FT&Kk`@X@LSi`}<-%>L+U~Lv2c%NEhdm&z2!aEk-J~gPmL!gvlnP2w zZydOAg#)j^OYDUw;1xLV4lrX6(573C2!Thkzp>}X@fXLA0YJ1zegmKi02UU)Vi~Iw zgzQw7WQ}_&h(hJ4K^G*%@C1S-Z_{BIFbw={4A8fG4vwG)DP%DJ{r0hS1nFKVyIv?g z^rKDU7M9vKC8z;hfCOCp>YrlW$1K+%#2tXzDw=kKT!xRi3}X-bxwv)Mhr2jR zg8NN>aSZV$=UYP0U3~Tq+(E2C1pZ=#n%9T9c@>b4A#`(I^z0{idE+!;jy`!w7^GRf z{#mRQil^33TUOaBSIUo_fgC%Tn~l=8JA6p3eK#9;tlyI|{HeR%{h&8Ks9wA+ z-cSVxeh*z9JqTi7j@xn+`>D#~XoF>ytkOYsV=`&()Hm&|?d#J`dvc?R`u5h&bXu}5 zU2WXlJB*&cn7o|6dWTa%5x8+HInVe5-lM`Kg#Cuol~JNi&9A>Kk?eGM;?|eqYjOGb zm=*}fMbiI`H5trjeM`wX?wK=;LmBt6hn}v23p1TNSa@MBFD zqkc+rwq#l^AqwOJc#uK|Zb1OUId5)Y1y})AfE8c`Sb={*0X(zGtRv2S-OD*EzzY1A z3ef&wVCDD=@DB-Q8;tLIM(^nfrSm>mlr#wqz@kyM82n z^rx@b15CGnD8o|0F`~VuyDNKr#enk%MR`5hZkxHS=GOyp{qT_HFBErA27k=$ck}T! zDC`yJp;80XtMi*8pRhNtNY2wAC4CeBXTKkXN!n<95lhRZl{058t726yR9?DWIdW4k z9VRVr@SJLoy|n9_@)IeeY1#9ihMm!N^~ysTr(PI$28tX89dvo|EQ|v=YRO?7Bx)R2 zcUV^0DsNZo|s5kp>VB&3ar&@q^4q$X-t zr!XR)|0D<-D{zVwSk|%D>Hh!d==cAp=!rN~R)7^asRE+ZcH1pvsZ)Icn@)Kf(+(yw o^2; Date: Tue, 31 Jan 2023 16:16:19 +0100 Subject: [PATCH 3/4] solution --- src/morse/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/morse/index.js b/src/morse/index.js index faae9d1..d1cdc90 100644 --- a/src/morse/index.js +++ b/src/morse/index.js @@ -57,7 +57,7 @@ const MORSE_CODE = { }; Object.freeze(MORSE_CODE); - + function morse(text) { let _morseArr = text.trim().split(" "); let _arrOfDecodedWords = _morseArr.map((item) => { From 3e14166d8f359e9c7cfd55eb16f7a9046fcd37bc Mon Sep 17 00:00:00 2001 From: Damilola Adegoke Date: Tue, 31 Jan 2023 16:17:29 +0100 Subject: [PATCH 4/4] solution