Skip to content

Commit 886fac9

Browse files
authored
Merge branch 'code-differently:main' into angie-lesson_06
2 parents 2143755 + 70dccf2 commit 886fac9

File tree

33 files changed

+6847
-2
lines changed

33 files changed

+6847
-2
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 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

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/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 -->

lesson_04/davidsmith/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Java Method
2+
```java
3+
public static boolean isPrime(int n) {
4+
if (n <= 1) return false;
5+
for (int i = 2; i <= Math.sqrt(n); i++) {
6+
if (n % i == 0) {
7+
return false;
8+
}
9+
}
10+
return true;
11+
}
12+
```
13+
## Python Method
14+
```python
15+
def is_prime(n):
16+
if n <= 1:
17+
return False
18+
for i in range(2, int(n**0.5) + 1):
19+
if n % i == 0:
20+
return False
21+
return True
22+
```
23+
24+
## Understanding The Code
25+
26+
Java and Python are similar in some ways. They have the same function structures. The `isPrime` method is in Java. The `is_prime` function is in Python. Both check if \( n \) is less than or equal to 1. They return false if this is true. Then, they use a for-loop. The for-loop finds factors from 2 to the square root of \( n \). Java needs explicit type declarations. Python does not need explicit type declarations. However, the logical flow is similar. This shows their focus on clarity. It makes both languages friendly for users. It also makes them easy for developers with different skills.
27+
28+
## Differences
29+
30+
Java and Python have big differences in syntax. They also have differences in structure. The `isPrime` method shows this. The `is_prime` function also shows this. Java is statically typed. It needs explicit type declarations like `int n`. Python is dynamically typed. It allows defining variables without a type. Java uses the `Math.sqrt` method. This method is for calculating square roots. Python uses the expression `n**0.5` for this. The for-loop syntax is different too. Java has a traditional for-loop with an initializer. Python uses the `range` function for loops. These differences show the different design philosophies. They also show different approaches to readability for each language.

lesson_04/jimoye244/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## Java implementation
2+
3+
```Java
4+
static boolean isPrimeNumber(int number){
5+
int zeroRemainderCount=0;
6+
for(int i=1; i <= number; i++){
7+
if(number % i == 0) zeroRemainderCount++;
8+
}
9+
10+
return zeroRemainderCount == 2 ? true : false;
11+
}
12+
13+
# Example usage:
14+
System.out.println(isPrimeNumber(7)) # Output: true
15+
System.out.println(isPrimeNumber(12)) # Output: false
16+
```
17+
18+
## JavaScript implementation
19+
20+
```javascript
21+
function isPrimeNumber(number){
22+
let zeroRemainderCount = 0;
23+
for(i=0; i<=number; i++){
24+
if(number % i === 0) zeroRemainderCount++;
25+
}
26+
return (zeroRemainderCount === 2) ? true : false;
27+
}
28+
29+
// Example usage:
30+
console.log(isPrimeNumber(11)); // Output: true
31+
console.log(isPrimeNumber(81)); // Output: false
32+
```
33+
34+
## Explanation
35+
36+
The Java implementation uses a function named `isPrimeNumber` that takes a single argument `number`. It returns `true` if the number is prime (e.g, when the zero remainder count of the division of the number by numbers between 1 and itself is two), otherwise, it returns `false`.
37+
38+
The JavaScript implementation uses a function named `isPrimeNumber` that also takes a single argument `number`. It returns `true` if the number is prime (using the same logic as the Java function) and `false` otherwise.
39+
40+
### Improvement in the Function Implementation:
41+
For large numbers, it will be reasonable to exit the loop once the zero remainder count reaches a value of 3.
42+
43+
### Differences
44+
45+
1. **Syntax**:
46+
- In Java, functions are defined by specifying the function name which is preceeded by the return type i.e `boolean isPrimeNumber`, whereas in JavaScript, the `function` keyword preeceds the function name i.e `boolean isPrimeNumber`.
47+
48+
The loop variable `i` was initialize with a value 0 that is type-annotated `int` in Java implementation. However, in JavaScript implementation, the variable `i` was not type-annotated.
49+
50+
2. **Equality Check**:
51+
- Java uses `double equal sign (==)` to test equality whereas JavaScript uses `tripple equal sign (===)` to test equality.
52+
53+
3. **Function Calls**:
54+
- The syntax for calling functions and printing to the console/output is slightly different. Java uses `System.out.println() or System.out.print()`, while JavaScript uses `console.log()`.
55+

lesson_04/josephcaballero/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
## Javascript Implementation
2+
```javascript
3+
const prime = (num) => {
4+
if(num <2){console.log(num + " is not a prime number")}
5+
else{
6+
for(let i = 2; i<=10; i++){
7+
if(num%i !== 0){
8+
if(i ===10){
9+
console.log(num + " is a prime number")
10+
break;
11+
}
12+
else{
13+
continue;
14+
}
15+
}
16+
else if(num%i===0 && num !==i){
17+
console.log(num + " is not a prime number")
18+
break;
19+
}
20+
else if(num===2){
21+
console.log(num + " is a prime number")
22+
break;
23+
}
24+
}
25+
}
26+
}
27+
prime(2) // output: 2 is a prime number
28+
prime(11) // output: 11 is a prime number
29+
prime(12) // output: 12 is not a prime number
30+
```
31+
## Python Implementation
32+
```python
33+
34+
def prime(num):
35+
if(num <2):
36+
print(num , " is not a prime number")
37+
else:
38+
for i in range(2,11):
39+
if num % i != 0:
40+
if i ==10:
41+
print(num , " is a prime number")
42+
break
43+
44+
else:
45+
continue
46+
47+
48+
elif num%i==0 and num !=i:
49+
print(num , " is not a prime number")
50+
break
51+
52+
elif num==2:
53+
print(num , " is a prime number")
54+
break
55+
else:
56+
continue
57+
58+
prime(2) # output: 2 is a prime number
59+
prime(11) # output: 11 is a prime number
60+
prime(113) # output: 113 is a prime number
61+
```
62+
63+
## Explanation
64+
My codes both use a function called prime with a parameter of num (num is to be filled with a number). The function is comprised of an if statement first with a condition that checks that the number entered isnt a number less than 2 (due to the fact that any number below 2 is not prime). Next is an else statement for when the number that was given in the parameter is not less than 2. After that is a for loop nested (meaning inside) in the else statement to iterate over a set group of numbers which in my case are 2-10 (because if a number is divided by these numbers and reaches 0 it is not a prime number, in the code it is shown as 2,11 however the digit on the right does not get reached and thus goes up to 10). Then if loops to meet certain conditions, in these if loops I use the percentage sign % which is modulator (mod for short) which checks if there is a remainder after division, be it 10/2 "which is 0" or 13/2 "which is 1" if there is a remainder it is prime and if there is not it is not prime(after all iterations). I used the code to take the number given to me and then checked if every number between 2-10 that was %(modded) by the given number did not meet 0 because if it did that would not be a prime number. To bypass the question of "what if the number you input gets iterated over in the for loop", i set a parameter that skips over that iteration by simply making use of the else loop so that any other iteration would be looked at and not that duplicate numbered one.
65+
66+
In python I did this using the def prime(): code "prime being the function name"
67+
68+
In javascript i did the exact same thing however I made a constant function which is just easier to debug. by doing const prime = (condition) => {code}
69+
70+
### Difference
71+
1. **Syntax**:
72+
- In python the syntax feels much more friendly by looking at it however is is alot scarier when you delve deep into it as you can make loops and function just by using if(condition): or for i in range(): as long as you are matching line indents, not to mention no ; which is alot more responsibility on the programmer
73+
- In javascript it feels much more safer but cluttered, the {} help show where exactly everything is in a more contained way but takes up space, and the ; are nice however they are an extra character, it is a give some take some scenario between these two languages
74+
2. **Different Signs**:
75+
- In Python you use different signs , like the print statement itself, how the statement is structured with a comma, and no parenthesis between most things that javascript would have
76+
- In Javascript the equivalent of print is console.log(), also in the log you put + to combine two values even if they arent the same to yield a log displayed in the console, and there are many more parenthesis like in the conditional statements

0 commit comments

Comments
 (0)