Skip to content

Commit 812f095

Browse files
committed
add another problems and solutions
1 parent e2382c7 commit 812f095

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@
3434
| Problem - 30 | [Thinkful-Logic](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-30.js) |
3535
| Problem - 31 | [You Need Only One](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-31.js) |
3636
| Problem - 32 | [Repeat str](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-32.js) |
37-
<!-- | Problem - 33 | | -->
37+
| Problem - 33 | [average of an array](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-33.js) |
38+
| Problem - 34 | [Reverse numbers](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-34.js) |
39+
| Problem - 35 | [A needla in haystack](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-35.js) |
40+
| Problem - 36 | [Rock Paper Scissors](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-36.js) |
41+
42+
<!-- | Problem - 37 | | -->

problem-33.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// calcul average of an array
2+
3+
function findAverage(array) {
4+
return array.length == 0 ? 0 : array.reduce((acc, curr) => acc + curr) / array.length;
5+
}

problem-34.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Convert number to reversed array of digits
2+
// Given a random non-negative number, you have to return
3+
// the digits of this number within an array in reverse order.
4+
5+
function digitize(n) {
6+
let numbers = n.toString();
7+
let strToArray =numbers.split('');
8+
let sortArray = strToArray.reverse().map(Number);
9+
console.log(sortArray)
10+
11+
12+
}
13+
digitize(35231)

problem-35.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// "found the needle at position " plus the index it found the needle, so:
2+
3+
function findNeedle(haystack) {
4+
let index = haystack.indexOf("needle")
5+
for(let i of haystack){
6+
if(i == "needle")
7+
return `found the needle at position ${index}`
8+
}
9+
}
10+

problem-36.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Rock Paper Scissors
2+
3+
4+
5+
M1
6+
const rps = (p1, p2) => {
7+
if(p1 == "scissors" && p2 == "paper" ||
8+
p1 == "rock" && p2 == "scissors" || p1 == "paper" && p2 == "rock")
9+
return "Player 1 won!"
10+
11+
else if(p1 == "scissors" && p2 == "rock" || p1 == "rock" && p2 == "paper" ||
12+
p1 == "paper" && p2 == "scissors" )
13+
return "Player 2 won!"
14+
else return "Draw!"
15+
};
16+
17+
18+
//M2
19+
const rps1 = (p1,p2) => {
20+
return p1 == "scissors" && p2 == "paper" ||
21+
p1 == "rock" && p2 == "scissors" ||
22+
p1 == "paper" && p2 == "rock" ? "Player 1 won!" : p1 == "scissors" && p2 == "rock" ||
23+
p1 == "rock" && p2 == "paper" ||
24+
p1 == "paper" && p2 == "scissors" ? "Player 2 won!" : "Draw!"
25+
}

0 commit comments

Comments
 (0)