Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
36870c5
Finished '3or5' from easy
iliask796 Aug 11, 2023
6950d54
Finished 'digitCount' from easy
iliask796 Aug 11, 2023
ae5a534
Finished 'factorial' from easy
iliask796 Aug 11, 2023
ac6d2c8
Finished 'makeSentence' from easy
iliask796 Aug 11, 2023
e1c9bf9
Finished 'miles' from easy
iliask796 Aug 11, 2023
f147394
Finished 'makeSentence' from easy
iliask796 Aug 11, 2023
0dee01f
Finished 'milesTravelled' from easy
iliask796 Aug 11, 2023
43f8535
Finished 'multiples' from easy
iliask796 Aug 11, 2023
707dd96
Finished 'random' from easy
iliask796 Aug 11, 2023
5ba5211
Finished range from easy
iliask796 Aug 11, 2023
ee145dc
Finished 'repeat' from easy
iliask796 Aug 12, 2023
c5f5ca9
Finished 'reverse' from easy
iliask796 Aug 12, 2023
7ef049c
Finished 'secondsInHours' from easy
iliask796 Aug 12, 2023
c2c45d6
Finished 'sum' from easy
iliask796 Aug 12, 2023
9ac6057
Finished 'sumOfCubes' from easy
iliask796 Aug 12, 2023
16f733c
Finished 'timesTables' from easy -> Finished all problems from easy
iliask796 Aug 12, 2023
921d305
Finished 'morseCode' from medium (Code + ReadMe)
iliask796 Aug 12, 2023
5f8e8c1
Finished 'fibonacci' from medium (Code + Plain)
iliask796 Aug 12, 2023
a96fe4c
Finished 'coins' from medium (Code + Plain)
iliask796 Aug 12, 2023
1935141
Finished 'romanNumerals' from medium (Code + Plain)
iliask796 Aug 12, 2023
43e1aad
Finished 'smallestProduct' from medium (Code + Plain)
iliask796 Aug 12, 2023
89a4876
Finished(?) 'castles' from hard (Code + ReadMe)
iliask796 Aug 12, 2023
e1eb6d6
Modified 'castles' from hard (Win Rate)
iliask796 Aug 13, 2023
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
4 changes: 4 additions & 0 deletions src/easy/3or5/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Plain English Solution

Starting from 1 going up to 1000, check if said number is multiple of 3 or 5.
If this is true then add this number to a sum.
When the process is done, return this sum.
7 changes: 7 additions & 0 deletions src/easy/3or5/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Pseudo Code Solution

```text
for each number from 1 to 1000
if number is multiple of 3 or multiple of 5
then increase sum by this number
return the sum
```
11 changes: 11 additions & 0 deletions src/easy/3or5/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function multOfThreeOrFive() {
let sum = 0
for (let i = 0; i < 1000; i++) {
if (i % 3 === 0 || i % 5 === 0) {
sum += i
}
}
return sum
}

console.log("The sum of all the multiples of 3 or 5 below 1000 is:", multOfThreeOrFive())
3 changes: 3 additions & 0 deletions src/easy/digitCount/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Plain English Solution

Keep dividing the number with 10 until it gets smaller than 1.
Digits of number are equal to the number of divisions we did.
6 changes: 6 additions & 0 deletions src/easy/digitCount/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Pseudo Code Solution

```text
while number is not less than 1
divide number by 10
increase digit count by 1
```
11 changes: 11 additions & 0 deletions src/easy/digitCount/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function digitCounter(num) {
let count = 0
while(num >= 1){
num /= 10
count++
}
return count
}

const givenNum = 314890
console.log('The number', givenNum, "has", digitCounter(givenNum), 'digits.')
4 changes: 4 additions & 0 deletions src/easy/factorial/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Plain English Solution

Recursively call a function to calculate the factorial.
Each time build up the product starting from the number and going down.
Stop when you reach the number 1, which is also the base case.
8 changes: 8 additions & 0 deletions src/easy/factorial/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Pseudo Code Solution

```text
Call function to calculate factorial of number
if number is 1
then return 1
else
return number * The factorial function with arguement number - 1
```
10 changes: 10 additions & 0 deletions src/easy/factorial/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function factorial(number) {
if (number === 1) {
return 1
} else {
return number * factorial(number - 1)
}
}

const givenNum = 5
console.log('The factorial of', givenNum, 'is', factorial(givenNum))
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

Get the first character of the sentence string and make it capital.
Check the last character of the sentence string.
If it is not some form of punctuation then add a full stop.
7 changes: 7 additions & 0 deletions src/easy/makeSentence/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Pseudo Code Solution

```text
Get the first character of string
Capitalize it and join it with the string again
If string's last character is a letter
then add a full stop
```
22 changes: 22 additions & 0 deletions src/easy/makeSentence/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function isLetter(char){
//If more things are considered as punctuation, they should be added.
const nonLetters = ['.', ',', '?', '!', ';']
for (let i = 0; i < nonLetters.length; i++) {
if (char === nonLetters[i]) {
return false
}
}
return true
}

function makeSentence(str) {
//Considering given sentence always starts with a letter.
str = str[0].toUpperCase() + str.slice(1)
if (isLetter(str[str.length-1])) {
str += '.'
}
return str
}

const givenStr = 'hello mate'
console.log('Turned', givenStr,'to',makeSentence(givenStr))
3 changes: 3 additions & 0 deletions src/easy/miles/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Plain English Solution

Use the 1.6:1 ratio to convert kilometers to miles.
Use Math built-in functions floor and ceiling to round the result.
9 changes: 9 additions & 0 deletions src/easy/miles/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# Pseudo Code Solution

```test
Divide kilometers by 1.6 to get result in miles
Calculate the remainder of miles with 1
If the remainder is below 0.5
then use Math.floor to round the result
Else
use Math.ceil to round the result
```
13 changes: 13 additions & 0 deletions src/easy/miles/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function toMiles(kilometers) {
const miles = kilometers / 1.6
remainder = miles % 1
if (remainder < 0.5) {
return Math.floor(miles)
} else {
return Math.ceil(miles)
}

}

const givenNum = 101
console.log(givenNum, 'kilometers equal to', toMiles(givenNum), 'miles.')
4 changes: 4 additions & 0 deletions src/easy/milesTravelled/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Plain English Solution

We are going to convert the given minutes to hours by dividing them by 60.
Then we are going to multiply that with the speed of journey (miles/hour).
Lastly we are going to round that and return the answer.
10 changes: 10 additions & 0 deletions src/easy/milesTravelled/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Pseudo Code Solution

```text
Divide minutes by 60 to get hours
Multiply hours with speed
If the decimal part of the above result is lower than 0.5
then use Math.floor to round
else
use Math.ceil to round
Return the result
```
15 changes: 15 additions & 0 deletions src/easy/milesTravelled/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function milesTravelled(minutes, speed) {
const hours = minutes / 60
const distance = hours * speed
const tmp = distance % 1
if (tmp < 0.5) {
return Math.floor(distance)
}
else {
return Math.ceil(distance)
}
}

const givenDuration = 140
const givenSpeed = 85
console.log("Travelled distance equals to", milesTravelled(givenDuration,givenSpeed), 'miles.')
3 changes: 3 additions & 0 deletions src/easy/multiples/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Plain English Solution

For as many times as length equals to, start by pushing given number in an array.
Every next time add the number to itself to create the next multiple.
9 changes: 9 additions & 0 deletions src/easy/multiples/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# Pseudo Code Solution

```text
initialize tmp with zero
initialize an empty array
for i = 1 to length going up by 1
add number to tmp
push into array the above result
return the array
```
13 changes: 13 additions & 0 deletions src/easy/multiples/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function multiples(number, len) {
let tmp = 0
const myArray = []
for (let i = 1; i <= len; i++) {
tmp += number
myArray.push(tmp)
}
return myArray
}

const givenNum = 12
const givenLen = 10
console.log('(', givenNum, ',', givenLen, ') -> ', multiples(givenNum, givenLen))
5 changes: 5 additions & 0 deletions src/easy/random/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Plain English Solution

We are going to use the computer's time to get the current milisecond.
Then we are going to calculate the remainder of that with the first given
number and add to that the difference of our two given numbers.
This way the random number is gonna be between the two given numbers' range.
7 changes: 7 additions & 0 deletions src/easy/random/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Pseudo Code Solution

```text
Get current milisecond
Divide it with the first number and get the remainder
Add the difference of the two given numbers to the remainder
Return the remainder
```
10 changes: 10 additions & 0 deletions src/easy/random/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//Supposing num1 is the low threshold and num2 is the high threshold
function random(num1, num2) {
let ms = new Date()
ms = ms.getMilliseconds() % num1
return ms + num2 - num1
}

const lowThreshold = 40
const highThreshold = 100
console.log('Random number between', lowThreshold, 'and', highThreshold, 'is', random(40, 100))
5 changes: 5 additions & 0 deletions src/easy/range/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Plain English Solution

We are going to set the first item of the list as both the highest and
the lowest number.
Then we are going to iterate the list and update the highest and lowest value.
Lastly we are going to return the difference between them.
10 changes: 10 additions & 0 deletions src/easy/range/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Pseudo Code Solution

```text
Set the first item of list to min and max
For i = 0 to list.length
if item > max
then max = item
if item < min
then min = item
Return max - min
```
18 changes: 18 additions & 0 deletions src/easy/range/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function range(numList) {
let min = numList[0]
let max = numList[0]
numList.forEach(
(listItem) => {
if (listItem > max) {
max = listItem
}
if (listItem < min) {
min = listItem
}
}
)
return max - min
}

const givenList = [10, 5, 7, 20, 3, 69, 22, -5, 75]
console.log('The range of given list is', range(givenList))
3 changes: 3 additions & 0 deletions src/easy/repeat/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Plain English Solution

Use the current string to build a new one. Traverse each letter of the string.
Use this letter twice and concentate them to create the required string.
8 changes: 8 additions & 0 deletions src/easy/repeat/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Pseudo Code Solution

```text
Initialize a new empty string
for i = 0 to given string.length
Get the character of string at pos i
Concentate two copies of that to the new string
return the new string
```
10 changes: 10 additions & 0 deletions src/easy/repeat/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function repeat(str) {
let result = ""
for (let i = 0; i < str.length; i++) {
result += str.charAt(i) + str.charAt(i)
}
return result
}

const givenStr = '1234!_ ?'
console.log(givenStr, '->', repeat(givenStr))
4 changes: 4 additions & 0 deletions src/easy/reverse/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Plain English Solution

Based on the examples, supposing the problem wanted to say reverse a "string" and not a "list" then:
Create a new empty string. Traverse the given string from the end to the start.
Concatenate each letter to the new string in order to create the result.
7 changes: 7 additions & 0 deletions src/easy/reverse/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Pseudo Code Solution

```text
Initialize a new empty string
For i = given str.length - 1 to 0 going backwards
Concatenate the character at position i with the new string
Return the result
```
10 changes: 10 additions & 0 deletions src/easy/reverse/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function reverse(str) {
let result = ""
for (let i = str.length-1; i >= 0; i--) {
result += str.charAt(i)
}
return result
}

const givenStr = 'string'
console.log(givenStr, '->', reverse(givenStr))
4 changes: 4 additions & 0 deletions src/easy/secondsInHours/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Plain English Solution

Divide the given seconds by 60 to convert to minutes.
Divide minutes by 60 to convert to hours.
The above in one step: Divide by 60*60=3600 and return result.
5 changes: 5 additions & 0 deletions src/easy/secondsInHours/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Pseudo Code Solution

```text
Divide given number by 3600
Return result
```
6 changes: 6 additions & 0 deletions src/easy/secondsInHours/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function secondsInHours(seconds) {
return seconds / 3600
}

givenTime = 16000
console.log(givenTime, 'second(s) equal to', secondsInHours(givenTime), 'hour(s).')
2 changes: 2 additions & 0 deletions src/easy/sum/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Plain English Solution

Run a loop from 1 to 100 summing up each number and return the result.
7 changes: 7 additions & 0 deletions src/easy/sum/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Pseudo Code Solution

```text
Initialize an empty sum
for i = 1 to 100 going up by 1
Add i to sum
return sum
```
9 changes: 9 additions & 0 deletions src/easy/sum/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function sum() {
let sum = 0
for (let i = 1; i <= 100; i++) {
sum += i
}
return sum
}

console.log("Sum of numbers from 1 to 100 is", sum())
3 changes: 3 additions & 0 deletions src/easy/sumOfCubes/plain.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Plain English Solution

Traverse through the list and keep the sum of each element to the power of three.
When finished, return the result.
8 changes: 8 additions & 0 deletions src/easy/sumOfCubes/pseudo.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Pseudo Code Solution

```text
Initialize a sum to zero value
for each element of the list
Calculate the cube of the element
Add it to the sum
return sum
```
Loading