diff --git a/src/isolate-duplicates/index.js b/src/isolate-duplicates/index.js index 79ae426..73cbdaa 100644 --- a/src/isolate-duplicates/index.js +++ b/src/isolate-duplicates/index.js @@ -1,3 +1,46 @@ -function isolateDuplicates(text) {} - +function isolateDuplicates(text) { + if(typeof text == 'string' && text.length !== 0) { + let duplicate = {}; + let extraAlpha = ""; + let str =''; + let count = 0; + let returnCount = []; + let string = text.toLowerCase() + + for (let i = 0; i < string.length; i++) { + if(extraAlpha != string[i]) { + if(duplicate[extraAlpha] > 2) { + str += ']' + + } + + duplicate[extraAlpha] = 0; + extraAlpha = string[i] + } + if(!duplicate[string[i]]) { + duplicate[string[i]] = 1; + + } else if(duplicate[string[i]] == 1) { + duplicate[string[i]]++ + + } else if(duplicate[string[i]] == 2) { + str += '[' + duplicate[string[i]]++ + count++ + } + + str += text[i] + } + if(duplicate[extraAlpha] > 2) { + str += ']' + } + + returnCount.push(str) + returnCount.push(count) + + return returnCount; + } else { + throw Error("Please enter a valid string"); + } +} module.exports = isolateDuplicates; diff --git a/src/morse/index.js b/src/morse/index.js index cf65063..ad50f12 100644 --- a/src/morse/index.js +++ b/src/morse/index.js @@ -58,6 +58,31 @@ const MORSE_CODE = { Object.freeze(MORSE_CODE); -function morse(text) {} +function morse(text) { + let morse = []; + let count = 0; + if(typeof text === 'string' && typeof text !== 'object') { + let newMorseCode = text.split(' ') + for(let i = 0; i < newMorseCode.length; i++) { + if(newMorseCode[i] == ''){ + count++ + }else { + count = 0; + } + if(newMorseCode[i] == '' && newMorseCode[i - 1] == '' && count == 2) { + morse.push(' ') + } else { + morse.push(MORSE_CODE[newMorseCode[i]]) + } + } + return morse.join('').trim(); + + } else if (text === '') { + return ''; + }else { + throw Error("Please provide a morse string"); + } + +} module.exports = morse; diff --git a/src/remove-dulplicates/index.js b/src/remove-dulplicates/index.js index 75c6c9b..fb40fa8 100644 --- a/src/remove-dulplicates/index.js +++ b/src/remove-dulplicates/index.js @@ -1,3 +1,20 @@ -function removeDuplicates(obj) {} +function removeDuplicates(obj) { + let arrOfString = []; + let finalObj = {}; + const newObjKeys = Object.keys(obj) + + for (let key = newObjKeys.length - 1; key >= 0; key--) { + let valueArr = obj[newObjKeys[key]] + let finalObject = []; + for(let value = 0; value < valueArr.length; value++) { + if(!arrOfString.includes(valueArr[value])) { + arrOfString.push(valueArr[value]) + finalObject.push(valueArr[value]) + } + } + finalObj[newObjKeys[key]] = finalObject + } + return finalObj; +} module.exports = removeDuplicates;