Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tunere Ereibor #175

Open
wants to merge 1 commit into
base: ereibor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/isolate-duplicates/index.js
Original file line number Diff line number Diff line change
@@ -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;
33 changes: 31 additions & 2 deletions src/morse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<text1.length; j++) {
if (text1[j] == "") continue result += MORSE_CODE[text1[j]]
}
if (i == text.length - 1) {
result1 += result } else {
result1 += result + ' ' }
}
return result1.trim()
} else {
text = text.trim()
if (text[text.length - 1] == ' '){
text = text.replace(' ', '')
}
text = text.split(' ')
for (let i = 0; i < text.length; i++) {
result += MORSE_CODE[text[i]]
}
return result }
}
console.log(morse(" ...---... -.-.-- - .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. .-.-.- "));
module.exports = morse;

14 changes: 12 additions & 2 deletions src/remove-dulplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function removeDuplicates(obj) {}

function removeDuplicates(obj) {
let c = [];
let diff = (a, b) => [...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;