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
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/isolate-duplicates/.DS_Store
Binary file not shown.
24 changes: 23 additions & 1 deletion src/isolate-duplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
function isolateDuplicates(text) {}
function isolateDuplicates(text) {
if (typeof text !== "string") {
return "Please enter a valid string";
}
let identical = "";
let countIdentical = 0;
for (let i = 0; i < text.length; i++) {
let j = i + 1;
let count = 0;
while (j < text.length && text[i] === text[j]) {
j++;
count++;
}
if (count > 2) {
identical += text[i] + "[" + text.slice(i + 1, j) + "]";
countIdentical++;
i = j - 1;
} else {
identical += text.slice(i, j);
}
}
return [identical, countIdentical];
}

module.exports = isolateDuplicates;
Binary file added src/morse/.DS_Store
Binary file not shown.
28 changes: 27 additions & 1 deletion src/morse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ const MORSE_CODE = {

Object.freeze(MORSE_CODE);

function morse(text) {}
function morse(text) {
if (Array.isArray(text)) {
throw new Error("Please provide a morse string");
return "Please provide a morse string";
}

if (typeof text === "undefined") {
throw new Error("Please provide a morse string");
return;
}

// split text by 3 spaces to break them into an array of words
let _morseArr = text.trim().split(" ");

let _arrOfDecodedWords = _morseArr.map((item) => {
let getMorseCodeFromItem = item.split(" ");

let getWordsFromItemArray = getMorseCodeFromItem.map((value) => {
let decodedLetter = MORSE_CODE[value];
return decodedLetter;
});

return getWordsFromItemArray.join("");
});

return _arrOfDecodedWords.join(" ");
}

module.exports = morse;
2 changes: 1 addition & 1 deletion src/morse/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const morseToText = require(".");
const morseToText = require("./index4");

describe("Morse assumptions", () => {
test("it returns an empty string untouched", () => {
Expand Down
14 changes: 13 additions & 1 deletion src/remove-dulplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
function removeDuplicates(obj) {}
function removeDuplicates(obj) {
let x = [];
let diff = (a, b) => [...new Set([...a].filter((x) => !b.includes(x)))];
return Object.entries(obj)
.reverse()
.map((entry) => {
const subCollector = x;
x = [...new Set([...x, ...entry[1]])];
return [entry[0], [...new Set(diff(entry[1], subCollector))]];
})
.reduce((arrays, array) => ((arrays[array[0]] = array[1]), arrays), {});

}

module.exports = removeDuplicates;