diff --git a/src/easy/digitCount/plain.md b/src/easy/digitCount/plain.md index 73370f1..f683ffc 100644 --- a/src/easy/digitCount/plain.md +++ b/src/easy/digitCount/plain.md @@ -1 +1,3 @@ # Plain English Solution + +I'd just use the .length method and hope it works on numbers. If it doesn't, I would split it into a list and then check the length. \ No newline at end of file diff --git a/src/easy/digitCount/pseudo.md b/src/easy/digitCount/pseudo.md index 520841f..96444c8 100644 --- a/src/easy/digitCount/pseudo.md +++ b/src/easy/digitCount/pseudo.md @@ -1 +1,3 @@ # Pseudo Code Solution + +log the length of numbers into the console \ No newline at end of file diff --git a/src/easy/digitCount/solution.js b/src/easy/digitCount/solution.js index e69de29..7b880a5 100644 --- a/src/easy/digitCount/solution.js +++ b/src/easy/digitCount/solution.js @@ -0,0 +1,9 @@ +// log the length of numbers into the console + +numbers = 12334 + +// console.log(numbers.length) – doesn't work! Time to convert it to a list + +// console.log(numbers.split('').length) - numbers can't be converted into a list this way either. String then? + +console.log(String(numbers).length) \ No newline at end of file diff --git a/src/easy/makeSentence/plain.md b/src/easy/makeSentence/plain.md index 73370f1..47821d0 100644 --- a/src/easy/makeSentence/plain.md +++ b/src/easy/makeSentence/plain.md @@ -1 +1,5 @@ # Plain English Solution + +Convert the string to a list. Get the first character of the sentence with the index [0]. Add the first character into a new variable, convert it into uppercase (if it's already uppercase, still convert it), and then popping it back with concatenation or unshift. Then check if the last character is punctuation, and if it is, leave the string alone, but if not, add a dot. + +If shifting a string doesn't work, I'll convert it to a list with .split and then reassemble it afterwards with a for loop. \ No newline at end of file diff --git a/src/easy/makeSentence/pseudo.md b/src/easy/makeSentence/pseudo.md index 520841f..6c024bc 100644 --- a/src/easy/makeSentence/pseudo.md +++ b/src/easy/makeSentence/pseudo.md @@ -1 +1,12 @@ # Pseudo Code Solution + +Target first character with [0] + +Put the shifted character into the upperCaseStart variable + +Make the upperCaseStart variable upper case + +Pop back upperCaseStart to the string with unshift or concatenation + +If the last character is not punctuation + – then add a dot \ No newline at end of file diff --git a/src/easy/makeSentence/solution.js b/src/easy/makeSentence/solution.js index e69de29..b0b27b2 100644 --- a/src/easy/makeSentence/solution.js +++ b/src/easy/makeSentence/solution.js @@ -0,0 +1,31 @@ +// Console log shifting a string, hopefully it works +let sentence = "this sentence is to be capitalized and a dot should be added to the end" + +let sentenceToList = sentence.split('') + +// Put the character into the upperCaseStart variable – update: don't even need to do that, can just uppercase directly + +let upperCaseStart = sentenceToList[0].toUpperCase() + +// Make the upperCaseStart variable upper case – done above + +// Pop back upperCaseStart to the string with unshift or concatenation + +sentenceToList.shift() + +sentenceToList.unshift(upperCaseStart) + +// If the last character is not punctuation +// – then add a dot + +if (sentenceToList[sentenceToList.length-1] !== '.' && sentenceToList[sentenceToList.length-1] !== '!' && sentenceToList[sentenceToList.length-1] !== '?' ) { + sentenceToList.push('.') +} + +let capStartFullStopSentence = '' + +for (let i of sentenceToList) { + capStartFullStopSentence += i +} + +console.log(capStartFullStopSentence) \ No newline at end of file diff --git a/src/easy/random/plain.md b/src/easy/random/plain.md index 73370f1..6b433d5 100644 --- a/src/easy/random/plain.md +++ b/src/easy/random/plain.md @@ -1 +1,9 @@ # Plain English Solution + +Start a min and max variable that our generator will generate between + +Use date.now() to generate a random number + +Loop through date.now() from the back (important since the back will be different all the time, the front will be the same) and if a number is found that is between min and max, then return that and break from the loop. + +This won't be able to generate negative numbers and numbers that are smaller than one. \ No newline at end of file diff --git a/src/easy/random/pseudo.md b/src/easy/random/pseudo.md index 520841f..f2b3d79 100644 --- a/src/easy/random/pseudo.md +++ b/src/easy/random/pseudo.md @@ -1 +1,9 @@ # Pseudo Code Solution + +Start a min and max variable that our generator will generate between + +Use date.now() to generate a random number + +Loop through date.now() from the back (important since the back will be different all the time, the front will be the same) and if a number is found that is between min and max, then return that and break from the loop. + +This won't be able to generate negative numbers and numbers that are smaller than one. \ No newline at end of file diff --git a/src/easy/random/solution.js b/src/easy/random/solution.js index e69de29..13c9dd1 100644 --- a/src/easy/random/solution.js +++ b/src/easy/random/solution.js @@ -0,0 +1,22 @@ +// Start a min and max variable that our generator will generate between + +function randomGenerator(min, max) { + + // Use date.now() to generate a random number + + const randomList = String(Date.now()).split('') + + // Loop through date.now() from the back (important since the back will be different all the time, the front will be the same) and if a number is found that is between min and max, then return that and break from the loop. + + + for (let i = randomList.length; i >= 0; i--) { + if (randomList[i] > min && randomList[i] < max) { + return randomList[i] + } + } +} + +console.log(randomGenerator(0, 9)) + +// This won't be able to generate negative numbers and numbers that are smaller than one. + diff --git a/src/easy/reverse/plain.md b/src/easy/reverse/plain.md index 73370f1..47c9c13 100644 --- a/src/easy/reverse/plain.md +++ b/src/easy/reverse/plain.md @@ -1 +1,3 @@ # Plain English Solution + +Loop through the elements of the string backwards, and add the current character to a new string. \ No newline at end of file diff --git a/src/easy/reverse/pseudo.md b/src/easy/reverse/pseudo.md index 520841f..85a9c5c 100644 --- a/src/easy/reverse/pseudo.md +++ b/src/easy/reverse/pseudo.md @@ -1 +1,9 @@ # Pseudo Code Solution + +Define empty newString + +Loop through the elements of a string backwards + +Add the characters to the empty newString + +Return newString \ No newline at end of file diff --git a/src/easy/reverse/solution.js b/src/easy/reverse/solution.js index e69de29..71b62cf 100644 --- a/src/easy/reverse/solution.js +++ b/src/easy/reverse/solution.js @@ -0,0 +1,18 @@ + + +function reverse(stringToReverse) { + + // Define empty newString + let reversedString = '' + + // Loop through the elements of a string backwards + for (let i = stringToReverse.length - 1; i >= 0; i--) { + // Add the characters to the empty newString + reversedString += stringToReverse[i] + } + + // Return newString + return reversedString +} + +console.log(reverse('123')) \ No newline at end of file diff --git a/src/medium/morseCode/plain.md b/src/medium/morseCode/plain.md index 73370f1..172966a 100644 --- a/src/medium/morseCode/plain.md +++ b/src/medium/morseCode/plain.md @@ -1 +1,8 @@ # Plain English Solution + +Create a function that converts letters to morse code with a million if statements + +Define a new empty string + +Loop through the elements of the input string + – use the function to add the correct morse code to a new string \ No newline at end of file diff --git a/src/medium/morseCode/pseudo.md b/src/medium/morseCode/pseudo.md index 520841f..159fd34 100644 --- a/src/medium/morseCode/pseudo.md +++ b/src/medium/morseCode/pseudo.md @@ -1 +1,8 @@ # Pseudo Code Solution + +Create a function that converts letters to morse code with a million if statements + +Define a new empty string + +Loop through the elements of the input string + – use the function to add the correct morse code to a new string \ No newline at end of file diff --git a/src/medium/morseCode/solution.js b/src/medium/morseCode/solution.js index e69de29..00d8c31 100644 --- a/src/medium/morseCode/solution.js +++ b/src/medium/morseCode/solution.js @@ -0,0 +1,73 @@ +function morseConverter(englishSentence) { + let morseSentence ='' // Define a new empty string + for (i of englishSentence.toLowerCase()) { // Loop through the elements of the input string + morseSentence += morseCharacterConverter(i) // – use the function to add the correct morse code to a new string + } + return morseSentence +} + +// Create a function that converts letters to morse code with a millio else if statements + +function morseCharacterConverter(englishLetter){ + let morseLetter = '' + if (englishLetter === 'a') { + morseLetter = ' .– ' + } else if (englishLetter === 'b') { + morseLetter = ' -... ' + } else if (englishLetter === 'c') { + morseLetter = ' -.-. ' + } else if (englishLetter === 'd') { + morseLetter = ' -.. ' + } else if (englishLetter === 'e') { + morseLetter = ' . ' + } else if (englishLetter === 'f') { + morseLetter = ' ..-. ' + } else if (englishLetter === 'g') { + morseLetter = ' --. ' + } else if (englishLetter === 'h') { + morseLetter = ' .... ' + } else if (englishLetter === 'i') { + morseLetter = ' .. ' + } else if (englishLetter === 'j') { + morseLetter = ' .--- ' + } else if (englishLetter === 'k') { + morseLetter = ' -.- ' + } else if (englishLetter === 'l') { + morseLetter = ' .-.. ' + } else if (englishLetter === 'm') { + morseLetter = ' -- ' + } else if (englishLetter === 'n') { + morseLetter = ' -. ' + } else if (englishLetter === 'o') { + morseLetter = ' --- ' + } else if (englishLetter === 'p') { + morseLetter = ' .--. ' + } else if (englishLetter === 'q') { + morseLetter = ' --.- ' + } else if (englishLetter === 'r') { + morseLetter = ' .-. ' + } else if (englishLetter === 's') { + morseLetter = ' ... ' + } else if (englishLetter === 't') { + morseLetter = ' - ' + } else if (englishLetter === 'u') { + morseLetter = ' ..- ' + } else if (englishLetter === 'v') { + morseLetter = ' ...- ' + } else if (englishLetter === 'w') { + morseLetter = ' .-- ' + } else if (englishLetter === 'x') { + morseLetter = ' -..- ' + } else if (englishLetter === 'y') { + morseLetter = ' -.-- ' + } else if (englishLetter === 'z') { + morseLetter = ' --.. ' + } else if (englishLetter === ' ') { + morseLetter = ' ' + } else { + morseLetter = '' + } + return morseLetter +} + +console.log(morseConverter("Hello, let's see if this works")) \ No newline at end of file diff --git a/src/medium/romanNumerals/solution.js b/src/medium/romanNumerals/solution.js index e69de29..6654c4a 100644 --- a/src/medium/romanNumerals/solution.js +++ b/src/medium/romanNumerals/solution.js @@ -0,0 +1,38 @@ +const romanNumeral = 'DCCCXXVIII' + +const valueMap = { + I: 1, + V: 5, + X: 10, + L: 50, + C: 100, + D: 500, + M: 1000 +} + +console.log(romanToArabicNumerals(romanNumeral)) + +function romanToArabicNumerals (roman) { + romanAsArray = roman.split('') // Splitting the input into a list + previousLetter = '' // Empty variable so we can see if we need to deduct in the future + arabicValue = 0 // Empty variable for the value total at the end + for (let i = 0; i < romanAsArray.length; i++) { + let currentLetter = romanAsArray[i] // new var in current iteration for easier readability + if (currentLetter === "V" && previousLetter === "I") { // huge if statemet for deducting value (there has to be a neater way) + arabicValue -= 2 + } else if (currentLetter === "X" && previousLetter === "I") { + arabicValue -= 2 + } else if (currentLetter === "L" && previousLetter === "X") { + arabicValue -= 20 + } else if (currentLetter === "C" && previousLetter === "X") { + arabicValue -= 20 + } else if (currentLetter === "D" && previousLetter === "C") { + arabicValue -= 200 + } else if (currentLetter === "M" && previousLetter === "C") { + arabicValue -= 200 + } + arabicValue += valueMap[currentLetter] || 0 // iterating through the map and adding the value + previousLetter = currentLetter // setting up the previous letter so we can check if we need to deduct stuff next iteration + } + return arabicValue +} \ No newline at end of file diff --git a/src/medium/romanNumerals/solutionWrongWay.js b/src/medium/romanNumerals/solutionWrongWay.js new file mode 100644 index 0000000..6f04d17 --- /dev/null +++ b/src/medium/romanNumerals/solutionWrongWay.js @@ -0,0 +1,50 @@ +number = 100 + +const oneDigitMap = { + 1: 'I', + 2: "II", + 3: "III", + 4: "IV", + 5: "V", + 6: "VI", + 7: "VII", + 8: "VIII", + 9: "IX" +} + +const twoDigitMap = { + 1: "X", + 2: "XX", + 3: "XXX", + 4: "XL", + 5: "L", + 6: "LX", + 7: "LXX", + 8: "LXXX", + 9: "XC" +} + +const threeDigitMap = { + 1: "C", + 2: "CC", + 3: "CCC", + 4: "CD", + 5: "D", + 6: "DC", + 7: "DCC", + 8: "DCCC", + 9: "CM" +} + +function arabicToRomanNumberals (number) { + numAsString = number.toString() + if (numAsString.length === 1) { + return oneDigitMap[numAsString] || "" + } else if (numAsString.length === 2) { + return twoDigitMap[numAsString[0]] || "" + oneDigitMap[numAsString[1]] || "" + } else if (numAsString.length === 3) { + return threeDigitMap[numAsString[0]] || "" + twoDigitMap[numAsString[1]] || "" + oneDigitMap[numAsString[2]] || "" + } +} + +console.log(arabicToRomanNumberals(number))