Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3a55d8c

Browse files
Merge pull request #3 from anasmak04/master
add another problems and solutions
2 parents 7ba7fe0 + 96d873e commit 3a55d8c

File tree

7 files changed

+86
-1
lines changed

7 files changed

+86
-1
lines changed

‎README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@
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+
| Problem - 37 | [sum of an array](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-37.js) |
42+
| Problem - 38 | [biggest number of an array](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-38.js) |
43+
44+
<!-- | Problem - 39 | | -->

‎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+
}

‎problem-37.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Take an array of integer data type of size 10 And pritn the sum of those 10 integers.
2+
3+
const solution = (array) => {
4+
let sum = array.reduce((acc,curr) => { return acc + curr},0)
5+
return sum;
6+
7+
};
8+
9+
console.log(solution([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); // 55
10+
console.log(solution([22, 11, 55, 66, 77, 88, 99, 44, 33, 10 ])); // 505
11+
console.log(solution([12, 12, 65, 36, 87, 18, 79, 14, 73, 70 ])); // 466

‎problem-38.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Say you are given the following array of integer data type.
2+
// Now write a program which will find the biggest integer and print the integer
3+
4+
5+
const solution = (array) => {
6+
let array1 = array.sort(function(a,b){return a - b})
7+
let biggest = array1[array1.length -1];
8+
return biggest;
9+
};
10+
11+
console.log(solution([10, 20, 30, 40, 50])); // 50
12+
console.log(solution([5, 10, 15, 20, 25, 30])); // 30
13+
console.log(solution([44, 665, 221, -434, 643, 123])); // 665
14+
console.log(solution([-34, 64, -1, 0, 45])); // 64

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /