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
2 changes: 2 additions & 0 deletions src/easy/digitCount/plain.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions src/easy/digitCount/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Pseudo Code Solution

log the length of numbers into the console
9 changes: 9 additions & 0 deletions src/easy/digitCount/solution.js
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions src/easy/makeSentence/plain.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 11 additions & 0 deletions src/easy/makeSentence/pseudo.md
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions src/easy/makeSentence/solution.js
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions src/easy/random/plain.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions src/easy/random/pseudo.md
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 22 additions & 0 deletions src/easy/random/solution.js
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 2 additions & 0 deletions src/easy/reverse/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Plain English Solution

Loop through the elements of the string backwards, and add the current character to a new string.
8 changes: 8 additions & 0 deletions src/easy/reverse/pseudo.md
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions src/easy/reverse/solution.js
Original file line number Diff line number Diff line change
@@ -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'))
7 changes: 7 additions & 0 deletions src/medium/morseCode/plain.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/medium/morseCode/pseudo.md
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions src/medium/morseCode/solution.js
Original file line number Diff line number Diff line change
@@ -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"))
38 changes: 38 additions & 0 deletions src/medium/romanNumerals/solution.js
Original file line number Diff line number Diff line change
@@ -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
}
50 changes: 50 additions & 0 deletions src/medium/romanNumerals/solutionWrongWay.js
Original file line number Diff line number Diff line change
@@ -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))