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
Empty file added .husky/lessons/gitone
Empty file.
Empty file added .husky/lessons/gittwo
Empty file.
137 changes: 137 additions & 0 deletions .husky/lessons/inex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// ## Morse

// The Morse code encodes every character as a sequence of "dots" and "dashes".

// For example, the letter A is coded as ·−, letter Q is coded as −−·−, and digit 1 is coded as ·−−−.

// The Morse code is case-insensitive, traditionally capital letters are used. When the message is written in Morse code, a single space is used to separate the character codes and 3 spaces are used to separate words.

// For example, the message `Decadev` in Morse code is -.. . -.-. .- -.. . ...-

// NOTE: Extra spaces before or after the code have no meaning and should be ignored. In addition to letters, digits and some punctuation, there are some special service codes, the most notorious of those is the international distress signal SOS (that was first issued by Titanic), that is coded as ···−−−···. These special codes are treated as single special characters, and usually are transmitted as separate words.
// Your task is to implement a function that would take the morse code as input and return a decoded human-readable string.

// For example.

// ```js
// decodeMorse("-.. . -.-. .- -.. . ...-");
// //should return "DECADEV"
// ```

// Use the constant `MORSE_CODE` below to translate.

// ```js

// const morseCode = {
// "-.-.--": "!",
// ".-..-.": '"',
// "...-..-": "$",
// ".-...": "&",
// ".----.": "'",
// "-.--.": "(",
// "-.--.-": ")",
// ".-.-.": "+",
// "--..--": ",",
// "-....-": "-",
// ".-.-.-": ".",
// "-..-.": "/",
// "-----": "0",
// ".----": "1",
// "..---": "2",
// "...--": "3",
// "....-": "4",
// ".....": "5",
// "-....": "6",
// "--...": "7",
// "---..": "8",
// "----.": "9",
// "---...": ":",
// "-.-.-.": ";",
// "-...-": "=",
// "..--..": "?",
// ".--.-.": "@",
// ".-": "A",
// "-...": "B",
// "-.-.": "C",
// "-..": "D",
// ".": "E",
// "..-.": "F",
// "--.": "G",
// "....": "H",
// "..": "I",
// ".---": "J",
// "-.-": "K",
// ".-..": "L",
// "--": "M",
// "-.": "N",
// "---": "O",
// ".--.": "P",
// "--.-": "Q",
// ".-.": "R",
// "...": "S",
// "-": "T",
// "..-": "U",
// "...-": "V",
// ".--": "W",
// "-..-": "X",
// "-.--": "Y",
// "--..": "Z",
// "..--.-": "_",
// "...---...": "SOS",
// };


// function morse (string) {

// let newCode = morseCode.trim()
// console.log(newCode)


// let a = "phil"
// let b = "grace"
// let c = "favour"

// console.log(`my name is ${a.charAt()} ${b}`)


var musicians = 0;


if (musicians <= 0) {
console.log("not a group");
} else if (musicians === 1) {
console.log("solo");
} else if (musicians === 2) {
console.log("duet");
} else if (musicians === 3) {
console.log("trio");
} else if (musicians === 4) {
console.log("quartet");
} else if (musicians >= 5) {
console.log("this is a large group");
}

console.log(musicians === 3)


// for (let i = 0; i < string.length; i++) {
// let code = "";
// if (morseCode[x] === Object.values(morseCode)) {
// return true;
// } else {
// return false
// }










// }
// console.log(morse[".."])
// // let newMorse = Object.values(morseCode);
// console.log(newMorse)
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 41 additions & 2 deletions src/isolate-duplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
function isolateDuplicates(text) {}
function isolateDuplicates(text) {
if (typeof text !== 'string') {
throw Error("Please enter a valid string");
}

let result = '';
let duplicateCount = 0;
let bracketCount = 0
let currentChar = '';

for (let i = 0; i < text.length; i++) {

module.exports = isolateDuplicates;
if (text[i].toLowerCase() === currentChar.toLowerCase()) {
if(duplicateCount == 1 ) {
result += '[';
bracketCount++
}
duplicateCount++;
} else {
if(duplicateCount > 1){
result += ']';
}
duplicateCount = 0;
}

currentChar = text[i];
result += currentChar;
}

for(let i = result.length - 1; i > 0; i--){
if(result[i] == '['){
result += ']';
return [result, bracketCount];
}else if(result[i] == ']'){
return [result, bracketCount];
}
}

return [result, bracketCount];
}

module.exports = isolateDuplicates;
48 changes: 45 additions & 3 deletions src/morse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,50 @@ const MORSE_CODE = {
"...---...": "SOS",
};

Object.freeze(MORSE_CODE);
// let txt = "";
// for (let x in MORSE_CODE) {
// txt += MORSE_CODE[x] ;
// console.log(txt)
// };

function morse(text) {}
// document.getElementById(txt);
// com

module.exports = morse;
// Object.freeze(MORSE_CODE);

// function morse(text) {}

// module.exports = morse;


// let text = "5";
// text = text.padStart(3,"0");

// document.getElementById("demo").innerHTML = text;
// console.log()

function morse(text) {

if(typeof text === 'string'){

const arr = text.split(' ');
const result = [];

for(let i of arr){
let currInnerArr = i.split(' ');
let currChar = [];
for(let j of currInnerArr){
currChar.push(MORSE_CODE[j])
}
result.push(currChar.join(''));
}

return result.join(' ').trim();

}else if(text === ""){
return "";
}
else {
throw Error("Please provide a morse string");
}
}
32 changes: 31 additions & 1 deletion src/remove-dulplicates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
function removeDuplicates(obj) {}
function removeDuplicates(obj) {

const newObj = {};
const objKeys = Object.keys(obj).reverse();

const prev = [];

for(let i= 0; i < objKeys.length; i++){
let newArr = []; // Contain for all unique characters in each arrays in object.
let curr = obj[objKeys[i]]; // Current array in each object.

for(let j = 0; j < curr.length; j++){
if(i === 0){
newArr.push(curr[j]);
prev.push(curr[j]);
}
if(i > 0 && !prev.includes(curr[j])){
newArr.push(curr[j]);
prev.push(curr[j]);
}
}

// Remove the duplicate and assign to object key
newObj[objKeys[i]] = newArr.reduce((a, b) => !a.includes(b) ? [...a, b] : a, []);

}

return newObj
}



module.exports = removeDuplicates;