diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..9c0ea4e Binary files /dev/null and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..01fa114 Binary files /dev/null and b/src/.DS_Store differ 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..d1cdc90 100644 --- a/src/morse/index.js +++ b/src/morse/index.js @@ -57,7 +57,21 @@ const MORSE_CODE = { }; Object.freeze(MORSE_CODE); + +function morse(text) { + let _morseArr = text.trim().split(" "); + let _arrOfDecodedWords = _morseArr.map((item) => { + let getMorseCodeFromItem = item.split(" "); -function morse(text) {} + 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;