File tree Expand file tree Collapse file tree 5 files changed +59
-1
lines changed Expand file tree Collapse file tree 5 files changed +59
-1
lines changed Original file line number Diff line number Diff line change 34
34
| Problem - 30 | [ Thinkful-Logic] ( https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-30.js ) |
35
35
| Problem - 31 | [ You Need Only One] ( https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-31.js ) |
36
36
| 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 | | -->
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments