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

init #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

init #182

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: 32 additions & 1 deletion src/isolate-duplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
function isolateDuplicates(text) {}
function isolateDuplicates(dup) {
if (dup === undefined) {
throw Error();
}
if (dup.length === 0) {
throw Error("Please enter a valid string");
}
let newArr = [];
let dupArr = [];
let count = 0;
let lower = dup.toLowerCase();
for (let i = 0; i < lower.length + 1; i++) {
if (lower[i - 1] === lower[i] && lower[i - 2] === lower[i]) {
dupArr.push(dup[i]);
} else {
if (dupArr.length !== 0) {
count += 1;
dupArr = dupArr.join("");
dupArr = `[${dupArr}]`;

newArr.push(dupArr);
}
newArr.push(dup[i]);
dupArr = [];
}
}
if (newArr[newArr.length - 1] === undefined) {
newArr.splice(newArr.length - 1, 1);
}

return [newArr.join("").toString(), count];
}

module.exports = isolateDuplicates;
43 changes: 42 additions & 1 deletion src/morse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,47 @@ const MORSE_CODE = {

Object.freeze(MORSE_CODE);

function morse(text) {}
function morse(text) {
if (text === "") {
return "";
}
if (text === undefined) {
throw Error();
}
if (text.length === 0) {
throw Error("Please provide a morse string");
}
let data = text.split(" ");
let output = [];

for (let i = 0; i < data.length; i++) {
output.push(MORSE_CODE[data[i]]);
}
let newArr = output;

for (let i = 0; i < output.length; i++) {
if (newArr[0] === undefined) {
newArr.shift();
}
if (newArr[output.length - 1] === undefined) {
newArr.pop();
}
}
for (let i = 0; i < newArr.length; i++) {
if (newArr[i] === 0 && newArr[i] === undefined) {
newArr[i] = newArr[i + 1];
}
if (newArr[i] === undefined && newArr[i + 1] === undefined) {
newArr[i] = " ";
i++;
} else if (newArr[i] === undefined) {
newArr[i] = "";
} else {
newArr[i] = newArr[i];
}
}

return newArr.join("");
}

module.exports = morse;
2 changes: 1 addition & 1 deletion src/morse/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe("Morse spec", () => {
});

test("it decodes letters with multiple spaces", () => {
expect(morseToText(" . ")).toBe("E");
expect(morseToText(" . . ")).toBe("E E");
expect(morseToText(" . ")).toBe("E");
expect(
morseToText(
" ...---... -.-.-- - .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. .-.-.- "
Expand Down
21 changes: 20 additions & 1 deletion src/remove-dulplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
function removeDuplicates(obj) {}
function removeDuplicates(obj) {
let compare = [],
newObject = {},
k = Object.keys(obj);

for (let i = k.length - 1; i >= 0; i--) {
let val = obj[k[i]],
newVal = [];

for (let j = 0; j < val.length; j++) {
if (!compare.includes(val[j])) {
compare.push(val[j]);
newVal.push(val[j]);
}
}

newObject[k[i]] = newVal;
}
return newObject;
}

module.exports = removeDuplicates;