Skip to content
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
47 changes: 45 additions & 2 deletions src/isolate-duplicates/index.js
Original file line number Diff line number Diff line change
@@ -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;
27 changes: 26 additions & 1 deletion src/morse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
19 changes: 18 additions & 1 deletion src/remove-dulplicates/index.js
Original file line number Diff line number Diff line change
@@ -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;