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
33 changes: 30 additions & 3 deletions src/isolate-duplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
function isolateDuplicates(text) {}

module.exports = isolateDuplicates;
function isolateDuplicates(text) {
if (typeof text !== 'string'){
throw new Error("Please enter a valid string");
}
let tracker = 0;
let array = []
let array2 = []
let newText = text.toUpperCase()

for(let i = 0; i < newText.length; i++){
if(newText[i] === newText[i-1] && newText[i] === newText[i+1] && newText[i-2] !== newText[i]){


array.push('[');
array.push(text[i]);
tracker += 1;
} else if (newText[i] === newText[i -1] && newText[i] === newText[i-2] && newText[i+1] !== newText[i]){
array.push(text[i]);
array.push(']')
tracker += 1;
} else {
array.push(text[i])
}
}
let stringOut = array.join('')
array2.push(stringOut, tracker)
return array2
}
console.log(isolateDuplicates("aaaabbcccadehhh"))
module.exports = isolateDuplicates;
37 changes: 36 additions & 1 deletion src/morse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,41 @@ const MORSE_CODE = {

Object.freeze(MORSE_CODE);

function morse(text) {}
decodeMorse = function(morseCode) {

if (typeof text !== "string"){
throw "Please provide a morse string"
} else if (text.length === 0){
return ""
}
let text2 = text.trim()
let morArr = text2.split(" ")
//
//console.log(morArr)

let strArr = []
let count = 0;
for (let i = 0; i < morArr.length; i++){
//console.log(MORSE_CODE[morArr[i]])
//console.log(morArr[i].trim())

let char = morArr[i]
if(char == ""){
count++
}else{
if(count>=2) strArr.push(" ");
//console.log(strArr)

strArr.push(MORSE_CODE[char]);
count = 0;

}
//console.log(strArr)
}

return strArr.join('')
}

console.log(morseCode("..- .-... .."))

module.exports = morse;
4 changes: 2 additions & 2 deletions src/remove-dulplicates/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Many duplicates
# Many duplicates

You are given an object, in which every property is an array of strings. E.g.

Expand All @@ -12,7 +12,7 @@ You are given an object, in which every property is an array of strings. E.g.
Create a function that returns an object with the same keys, but each string can only appear once. E.g.

```json
{
{
"1": ["C"],
"2": ["A", "B", "D"]
}
Expand Down
22 changes: 20 additions & 2 deletions src/remove-dulplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
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;
console.log(removeDuplicates({
"432": ["A", "A", "B", "D"],
"53": ["L", "G", "B", "C"],
"236": ["L", "A", "X", "G", "H", "X"],
"11": ["P", "R", "S", "D"]
}))

module.exports = removeDuplicates;