Skip to content

Commit f8c8e42

Browse files
authored
Merge branch 'code-differently:main' into Shawn-lesson06
2 parents f590275 + d12e7a3 commit f8c8e42

File tree

66 files changed

+13784
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+13784
-15
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"ms-dotnettools.csdevkit",
3636
"ritwickdey.LiveServer",
3737
"mechatroner.rainbow-csv",
38-
"alexcvzz.vscode-sqlite"
38+
"alexcvzz.vscode-sqlite",
39+
"Orta.vscode-jest",
40+
"firsttris.vscode-jest-runner"
3941
],
4042
"settings": {
4143
"terminal.integrated.defaultProfile.linux": "zsh",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Check Lesson 05 Quiz Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths:
7+
- "lesson_05/quiz/**"
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Use Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20.x'
23+
24+
- name: Build Shared Lib with Node.js
25+
working-directory: ./lib/typescript/codedifferently-instructional
26+
run: npm ci
27+
28+
- name: Build Lesson 06 with Node.js
29+
working-directory: ./lesson_05/quiz
30+
run: |
31+
npm ci
32+
npm run check
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Check Lesson 06 Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths:
7+
- "lesson_06/expression/**"
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Use Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20.x'
23+
24+
- name: Build Shared Lib with Node.js
25+
working-directory: ./lib/typescript/codedifferently-instructional
26+
run: npm ci
27+
28+
- name: Build Lesson 06 with Node.js
29+
working-directory: ./lesson_06/expression
30+
run: |
31+
npm ci
32+
npm run check
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Check Lesson 07 Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths:
7+
- "lesson_07/conditionals/**"
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Use Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20.x'
23+
24+
- name: Build Shared Lib with Node.js
25+
working-directory: ./lib/typescript/codedifferently-instructional
26+
run: npm ci
27+
28+
- name: Build Lesson 07 with Node.js
29+
working-directory: ./lesson_07/conditionals
30+
run: |
31+
npm ci
32+
npm run check

.github/workflows/check_push.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,16 @@ jobs:
5656
npm run compile
5757
npm run lint
5858
59+
- name: Build Lesson 06 with Node.js
60+
working-directory: ./lesson_06/expression
61+
run: |
62+
npm ci
63+
npm run compile
64+
65+
- name: Build Lesson 07 with Node.js
66+
working-directory: ./lesson_07/conditionals
67+
run: |
68+
npm ci
69+
npm run compile
70+
5971

README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

lesson_04/amiyahjones/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Javascript
2+
``` javascript
3+
4+
function isPrime(num) {
5+
if (num < 2) {
6+
return false; // Numbers less than 2 are not prime
7+
}
8+
9+
for (let i = 2; i < num; i++) {
10+
if (num % i === 0) {
11+
return false;
12+
}
13+
}
14+
15+
return true;
16+
}
17+
18+
console.log(isPrime(5)); //true
19+
console.log(isPrime(1)); //false
20+
21+
```
22+
## Ruby
23+
###### Tutorial used : https://www.youtube.com/watch?v=33pLqGvk-PM
24+
``` ruby
25+
def prime?(n)
26+
# '2..n-1' checks all the numbers from 2 up to less than 'n'.
27+
# 'none' -> sees if none of these numbers can divide 'n' evenly.
28+
(2..n-1).none? {|divisor| n % divisor == 0}
29+
# If none of these numbers divide 'n' without a remainder,
30+
# then 'n' is a prime number. Otherwise, it's not.
31+
end
32+
33+
p prime? 5 # prints 'true'
34+
p prime? 6 # prints 'false'
35+
p prime? 7 # also 'true'
36+
```
37+
38+
39+
## Explanation
40+
41+
My JavaScript implementation uses a function named ```isPrime``` that checks if a number is prime by first returning `false` if the number is less than 2, since prime numbers are greater than 1. Then, it tests every number from 2 up to one less than the given number to see if any of them can divide it without leaving a remainder. If it finds one that can divide it evenly, it returns `false` ; if not, it returns `true`, meaning the number is prime.
42+
43+
The ruby implementation has a function named ```prime?``` that also looks at all the numbers from 2 up to one less than the number given. Same rules apply: If none of those numbers can divide it evenly, then it prints ```true```. For example, it tells us if 5 and 7 are prime (they are!) and if 6 is prime (it’s not!).
44+
45+
### Differences
46+
1. Instead of ```function``` used to define what your function is in javascript, Ruby use ```def```
47+
2. Ruby is much more simple - where tthe ```if``` and ```else``` statement is simply in one line
48+
3. Ruby simply 'prints' the result of its functions rather than ```console.log();```
49+
50+

lesson_04/chelseaogbonnia/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Prime Number Finder (Python and JavaScript) #
2+
3+
This project demonstrates how to find prime numbers between 1 and 100 using two programming languages: Python and JavaScript. Each function uses a for loop to check whether a number is prime, and both include inline comments to explain the code step by step. Additionally, there are detailed explanations after each function.
4+
5+
## Prime Number Finder in Python ##
6+
```
7+
# Function to find prime numbers between 1 and 100 in Python
8+
def find_prime_num_py():
9+
10+
# Loop through numbers from 2 to 100
11+
for num in range(2, 101):
12+
is_prime = True # Assume the number is prime
13+
14+
# Check if num is divisible by any number between 2 and its square root
15+
for i in range(2, int(num**0.5) + 1):
16+
if num % i == 0:
17+
is_prime = False # If divisible, not a prime number
18+
break # Exit the loop early
19+
20+
# If is_prime is still true, num is a prime number
21+
if is_prime:
22+
print(num) # Output the prime number
23+
24+
# Call the Python function
25+
find_prime_num_py()
26+
```
27+
### Python Explanation: ###
28+
The Python function, find_prime_num_py, uses a for loop to iterate through the numbers between 2 and 100. The is_prime variable is set to True for each number. Inside the inner loop, we check if the number is divisible by any integer between 2 and the square root of the number. If the number is divisible, it is marked as not prime, and we break out of the inner loop to stop further unnecessary checks. The square root limit ensures better performance. When the number is confirmed to be prime, it is printed to the console.
29+
30+
31+
## Prime Number Finder in JavaScript ##
32+
```
33+
// Function to find prime numbers between 1 and 100 in JavaScript
34+
function findPrimeNumberJS() {
35+
36+
// Loop through numbers from 2 to 100
37+
for (let num = 2; num <= 100; num++) {
38+
let isPrime = true; // Assume the number is prime
39+
40+
// Check if num is divisible by any number between 2 and its square root
41+
for (let i = 2; i <= Math.sqrt(num); i++) {
42+
if (num % i === 0) {
43+
isPrime = false; // If divisible, not a prime number
44+
break; // Exit the loop early
45+
}
46+
}
47+
48+
// If isPrime is still true, num is a prime number
49+
if (isPrime) {
50+
console.log(num); // Output the prime number
51+
}
52+
}
53+
}
54+
55+
// Call the JavaScript function
56+
findPrimeNumberJS();
57+
```
58+
59+
### JavaScript Explanation: ###
60+
In this JavaScript function, findPrimeNumberJS, we use a for loop to iterate over the numbers from 2 to 100. The isPrime variable initially assumes that each number is prime. For each number num, we check if it is divisible by any number from 2 to the square root of num. If the number is divisible, it is marked as not prime by setting isPrime to false, and we break out of the inner loop to save time. If the number remains prime after the check, it is printed to the console. The square root check ensures we minimize the number of iterations for efficiency.
61+
62+
## Similarities and Differences Between Python and JavaScript Prime Number Functions ##
63+
64+
### Similarities
65+
66+
* Logic (Using Square Roots to Check Primes): Both functions in Python and JavaScript use the same fundamental logic to determine if a number is prime. By checking divisors only up to the square root of the number, we can efficiently reduce the number of checks. This optimization works in both languages because if a number has a divisor greater than its square root, it must also have a corresponding smaller divisor, which would have been checked already.
67+
68+
* Looping Structure: Both functions use a for loop to iterate over potential divisors, starting from 2. While the exact syntax differs, the purpose is the same—to test whether the number is divisible by any number within this range. If no divisor is found, the number is prime.
69+
70+
71+
### Differences:
72+
73+
* Syntax: Python uses range() to generate numbers in a loop, while JavaScript directly declares the loop variable and sets its conditions. Python also uses indentation to define code blocks, while JavaScript uses curly braces {}.
74+
75+
* Case Sensitivity: Python commonly uses snake_case for function and variable names (e.g., is_prime), while JavaScript typically uses camelCase (e.g., isPrime).
76+
77+
* Variable Declarations: In Python, variables are declared by simply assigning a value to them (e.g., num = 5). In JavaScript, variables must be explicitly declared using let, const, or var (e.g., let num = 5).

lesson_04/chigazograham/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## Python implementation
2+
3+
```python
4+
def is_prime(num):
5+
# uses the function is_prime and takes the argument num
6+
if num > 1:
7+
# gets rid of numbers 1 and lower as the first prime number is 2
8+
for i in range(2, (num // 2) + 1):
9+
# tells the computer to look at all numbers between 2 and half of the value of num rounded up to the next nearest value using floor division
10+
if(num % i) == 0:
11+
# then divides the num value, using modulo division, by every number in the range of two to +infinity
12+
return False
13+
# if the remainder in equivalent to 0 then the number is not prime and returns False
14+
else:
15+
return True
16+
# if the remaineder is not equivalent to 0 then the terminal will return True
17+
else:
18+
return False
19+
# for all other real numbers that arent prime the terminal will reurn False
20+
21+
print(is_prime(19)) #Output: True
22+
print(is_prime(9)) #Output: False
23+
```
24+
25+
## Ruby implementation
26+
27+
```ruby
28+
def isPrime(n)
29+
#uses the function isPrime and takes the argument n
30+
return false if n <= 1
31+
#the computer will reurn false for all numbers less than or equal to zero
32+
return true if n == 2 || n == 3
33+
#tells the computer to return true if the n is equivalent to 2 or 3
34+
35+
return false if n % 2 == 0 || n % 3 == 0
36+
#returns false if n is divisible by two or 3
37+
38+
i = 5
39+
#defines i starting value as 5
40+
while i * i <= n
41+
#while n is greater than or equal to 25
42+
return false if n % i == 0 || n % (i + 2) == 0
43+
#return false if n is divisible by 5 or 7
44+
i += 6
45+
#adds 6 to the value of i if n is not divisible by 5 or 7 and runs the loop again
46+
end
47+
true
48+
#returns true for all numbers that arent divisible by 2, 3, 5, or 7
49+
end
50+
puts isPrime(17) #Output: true
51+
puts isPrime(24) #Output: false
52+
```
53+
54+
## Explanation
55+
56+
The Python implementation uses a function named `is_prime` that takes a single argument `num`. It returns `False` if the number is 1 or less or divisible by any number from two to half the value of `num` (i.e., when the remainder of the division of the number by 2 is zero), otherwise, it returns `True` and returns any possible other values as false.
57+
58+
The Ruby implementation uses a function named `isPrime` that also takes a single argument `n`. It returns `true` if the number is equivalent to 2 or 3 and if the number is not divisible by 2 or 3 and 5 or 7 if the number is over 25 and `false` if otherwise.
59+
60+
### Differences
61+
62+
1. **Syntax**:
63+
- Python uses `True` and `False` for boolean values, while Ruby uses `true` and `false`.
64+
- The formatting for `if` statements are also different between the two. In Python, `if` statements have the initial statement and then on the next line the command to run if the variable falls under the `if` statement. In Ruby the formatting is completely different, the command comes first and after that the `if` statement comes in on the same line
65+
- In Python, a colon(`:`) is used to close function statements, whereas in Ruby there is nothing closing the function statements.
66+
- Ruby can return true or false without a return statement. In contrast Python requires a return statement or will return with `None`.
67+
- Ruby has to be closed in `end` after loops or an error will appear and the code won't run. Python, on the other hand doesn't need anything and will return with `None` instead of an error if not given further instructions.
68+
- The syntax for calling functions and printing to the console/output is different. Python uses `print()`, while Ruby uses `puts()`.
69+
70+
<!-- Used code from geeksforgeeks.org to assist in creating assignment -->

0 commit comments

Comments
 (0)