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

if (text === undefined){
throw Error();
}
if (text.length === 0) {
throw Error ("Please enter a valid string");
}
let firstArr = [];
let secondArr = [];
let count = 0;
let str = text.toLowerCase();

for (let i = 0; i < str.length + 1; i++) {
if (str[i - 1] === str[i] && str[i - 2] === str[i]) {
secondArr.push(text[i]);
}
else {
if (secondArr.length !== 0) {
count += 1;
secondArr = secondArr.join("");
//secondArr.push
firstArr.push(`[${secondArr}]`);
}
if (secondArr.length !== undefined){
firstArr.push(text[i]);
}
secondArr = [];
}
}
if (secondArr.length !== 0){
count += 1;
secondArr = secondArr.join("");
firstArr.push(`[${secondArr}]`)
}
return [firstArr.join(""), count]
}

let userInput = "hellllloooooodeeeecadevvsss" //prompt("Enter a string:");
let result = isolateDuplicates(userInput);

console.log(result);


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

Object.freeze(MORSE_CODE);

function morse(text) {}
function morse(text) {
if(text === ""){
//console.log(text)
return "";
}
if(text === undefined) {
//console.log(text)
throw Error ()
}
if (text.length === 0){
throw Error('Please provide a morse string')
}
if (typeof text == "string" ) {
console.log(text)
if (text.includes('-') || text.includes('.')) {
// Input is Morse code, decode to text
const words = text.trim().split(' ');

const decodedMorse = words.map(word => {
const sequences = word.split(' ');

const decodedCharacters = sequences.map(sequence => {
return MORSE_CODE[sequence];
});
//console.log(decodedCharacters)
return decodedCharacters.join('');
});
//console.log(decodedMorse)
return decodedMorse.join(' ');
// } else {
// throw new Error('Please provide a Morse code string.');
}

}
}

const morseCode = "-.. . -.-. .- -.. . ...-";
const decodedMessage = morse(morseCode); // Pass the morseCode as input to the function
console.log(decodedMessage);
console.log(morse(''))

console.log(typeof [])


module.exports = morse;
81 changes: 80 additions & 1 deletion src/remove-dulplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,82 @@
function removeDuplicates(obj) {}
function removeDuplicates(obj) {
let outputObject = {};

let sortedKeys = Object.keys(obj).map(key => Number(key)).sort((a, b) => b - a);
console.log(sortedKeys)
sortedKeys.forEach(key => {
let inputArray = obj[key];
let uniqueArray = [];

inputArray.forEach(item => {
// Check if the item is already in the uniqueArray or any other array
if (!uniqueArray.includes(item) && !isStringInOtherArray(outputObject, item, key)) {
uniqueArray.push(item);
}
});

if (uniqueArray.length >= 0) {
outputObject[key] = uniqueArray;
}
});

return outputObject;
}

// Helper function to check if a string is in any other array
function isStringInOtherArray(object, item, currentKey) {
for (let key in object) {
if (object.hasOwnProperty(key) && key !== currentKey) {
if (object[key].includes(item)) {
return true;
}
}
}
return false;
}


// Helper function to check if a string is in any other array
function isStringInOtherArray(object, item, currentKey) {
for (let key in object) {
if (object.hasOwnProperty(key) && key !== currentKey) {
if (object[key].includes(item)) {
return true;
}
}
}
return false;
}

let arryObj = {
"4": ["A"],
"10": ["B"],
"3": ["C"],
"1": ["D"],
"2": ["E"],
"26": ["F", "Z"],
"5": ["G"],
"8": ["H"],
"11": ["I", "B"],
"12": ["J", "I"],
"13": ["K", "J"],
"14": ["L", "K"],
"15": ["M", "L"],
"7": ["N"],
"6": ["O"],
"16": ["P", "M"],
"9": ["Q"],
"17": ["R", "P"],
"18": ["S", "R"],
"19": ["T", "S"],
"20": ["T", "U"],
"21": ["V", "T"],
"22": ["W", "V"],
"23": ["X", "W"],
"24": ["X", "Y"],
"25": ["Y", "Z"],
};

let result = removeDuplicates(arryObj);
console.log(result);

module.exports = removeDuplicates;