Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add another problems and solutions
  • Loading branch information
anasmak04 committed Nov 10, 2022
commit 812f095c0b8ede2f159337537fcf5bbae0502f4f
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@
| Problem - 30 | [Thinkful-Logic](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-30.js) |
| Problem - 31 | [You Need Only One](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-31.js) |
| Problem - 32 | [Repeat str](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-32.js) |
<!-- | Problem - 33 | | -->
| Problem - 33 | [average of an array](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-33.js) |
| Problem - 34 | [Reverse numbers](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-34.js) |
| Problem - 35 | [A needla in haystack](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-35.js) |
| Problem - 36 | [Rock Paper Scissors](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-36.js) |

<!-- | Problem - 37 | | -->
5 changes: 5 additions & 0 deletions problem-33.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// calcul average of an array

function findAverage(array) {
return array.length == 0 ? 0 : array.reduce((acc, curr) => acc + curr) / array.length;
}
13 changes: 13 additions & 0 deletions problem-34.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Convert number to reversed array of digits
// Given a random non-negative number, you have to return
// the digits of this number within an array in reverse order.

function digitize(n) {
let numbers = n.toString();
let strToArray =numbers.split('');
let sortArray = strToArray.reverse().map(Number);
console.log(sortArray)


}
digitize(35231)
10 changes: 10 additions & 0 deletions problem-35.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// "found the needle at position " plus the index it found the needle, so:

function findNeedle(haystack) {
let index = haystack.indexOf("needle")
for(let i of haystack){
if(i == "needle")
return `found the needle at position ${index}`
}
}

25 changes: 25 additions & 0 deletions problem-36.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Rock Paper Scissors



M1
const rps = (p1, p2) => {
if(p1 == "scissors" && p2 == "paper" ||
p1 == "rock" && p2 == "scissors" || p1 == "paper" && p2 == "rock")
return "Player 1 won!"

else if(p1 == "scissors" && p2 == "rock" || p1 == "rock" && p2 == "paper" ||
p1 == "paper" && p2 == "scissors" )
return "Player 2 won!"
else return "Draw!"
};


//M2
const rps1 = (p1,p2) => {
return p1 == "scissors" && p2 == "paper" ||
p1 == "rock" && p2 == "scissors" ||
p1 == "paper" && p2 == "rock" ? "Player 1 won!" : p1 == "scissors" && p2 == "rock" ||
p1 == "rock" && p2 == "paper" ||
p1 == "paper" && p2 == "scissors" ? "Player 2 won!" : "Draw!"
}