diff --git a/src/isolate-duplicates/index.js b/src/isolate-duplicates/index.js index 79ae426..ce9a997 100644 --- a/src/isolate-duplicates/index.js +++ b/src/isolate-duplicates/index.js @@ -1,3 +1,26 @@ -function isolateDuplicates(text) {} +function isolateDuplicates(text) { + + if (typeof (text) !== "string") { + throw new Error('Please enter a valid string') + } + + let finalStr = '' + let count = 0 + let newText = text.toLowerCase() + for (let j = 0; j < text.length; j++) { + finalStr += text[j] + + if (newText[j] === newText[j - 1] && newText[j] === newText[j + 1] && newText[j] !== newText[j - 2]) { + finalStr += '[' + count += 0.5 + } + + if (newText[j] === newText[j - 1] && newText[j] !== newText[j + 1] && newText[j] === newText[j - 2]) { + finalStr += ']' + count += 0.5 + } + } + return [finalStr, count] +} module.exports = isolateDuplicates; diff --git a/src/morse/index.js b/src/morse/index.js index cf65063..d614bfa 100644 --- a/src/morse/index.js +++ b/src/morse/index.js @@ -58,6 +58,14 @@ 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') + } else { + text = text.trim().split(' '); + let translatedCode; + translatedCode = text.map(a => a.split(' ').map(b => MORSE_CODE[b]).join('')).join(' ') + return translatedCode; + } +} module.exports = morse; diff --git a/src/remove-dulplicates/index.js b/src/remove-dulplicates/index.js index 75c6c9b..cba99b3 100644 --- a/src/remove-dulplicates/index.js +++ b/src/remove-dulplicates/index.js @@ -1,3 +1,28 @@ -function removeDuplicates(obj) {} +function removeDuplicates(obj) { + let arr = Object.entries(obj) + let newArr + let keysArr = [] + let valuesArr = [] + let c = [] + let diff = (a, b) => [...new Set([...a].filter((x) => !b.includes(x)))]; + + for (let index = 0; index < arr.length; index++) { + keysArr.push(arr[index][0]) + newArr = [...new Set(arr[index][1])] + valuesArr.push(newArr) + } + let finalArr = valuesArr.reverse().map((value) => { + const subCollector = c; + c = [...new Set([...c, ...value])]; + return [...new Set(diff(value, subCollector))] + }) + finalArr = finalArr.reverse() + const newObj = {} + keysArr.forEach((element, index) => { + let newElement = element + newObj[newElement] = finalArr[index] + }) + return newObj +} module.exports = removeDuplicates; diff --git a/tsconfig.json b/tsconfig.json index ee19d46..b2dfb5b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ @@ -25,7 +25,7 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ + "module": "commonjs" /* Specify what module code is generated. */, // "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ @@ -39,7 +39,7 @@ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ /* JavaScript Support */ - "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + "allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */, // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ @@ -47,11 +47,11 @@ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ // "declarationMap": true, /* Create sourcemaps for d.ts files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + "sourceMap": true /* Create source map files for emitted JavaScript files. */, // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ // "outDir": "./", /* Specify an output folder for all emitted files. */ // "removeComments": true, /* Disable emitting comments. */ - "noEmit": true, /* Disable emitting files from a compilation. */ + "noEmit": true /* Disable emitting files from a compilation. */, // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ @@ -71,12 +71,12 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ + "strict": true /* Enable all strict type-checking options. */, // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ @@ -98,6 +98,6 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ } }