diff --git a/src/isolate-duplicates/index.js b/src/isolate-duplicates/index.js index 79ae426..a10900c 100644 --- a/src/isolate-duplicates/index.js +++ b/src/isolate-duplicates/index.js @@ -1,3 +1,18 @@ -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..8605a7a 100644 --- a/src/morse/index.js +++ b/src/morse/index.js @@ -58,6 +58,35 @@ const MORSE_CODE = { Object.freeze(MORSE_CODE); -function morse(text) {} - +function morse(text) { + if (typeof(text) != 'string') { + throw new Error("Please provide a morse string"); + } + if (text == "" ) return "" let result = "" let result1 = "" text = text.trim() + if (text.includes(' ')) { + text = text.replace(/ /g, '[[]]') + text = text.split('[[]]') + for (let i = 0; i < text.length; i++) { + let text1 = text[i].split(' ') + result = "" for (let j=0; j [...new Set([...a].filter((x) => !b.includes(x)))]; + return Object.entries(obj) + .reverse() + .map((entry) => { + const subCollector = c; + c = [...new Set([...c, ...entry[1]])]; + return [entry[0], [...new Set(diff(entry[1], subCollector))]]; + }) + .reduce((arrays, array) => ((arrays[array[0]] = array[1]), arrays), {}); + } module.exports = removeDuplicates;