Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@
| 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 | [sum of an array](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-37.js) |
| Problem - 38 | [biggest number of an array](https://github.com/anasmak04/Problem-solving-with-JavaScript/blob/master/problem-38.js) |

<!-- | Problem - 39 | | -->
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!"
}
11 changes: 11 additions & 0 deletions problem-37.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Take an array of integer data type of size 10 And pritn the sum of those 10 integers.

const solution = (array) => {
let sum = array.reduce((acc,curr) => { return acc + curr},0)
return sum;

};

console.log(solution([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); // 55
console.log(solution([22, 11, 55, 66, 77, 88, 99, 44, 33, 10 ])); // 505
console.log(solution([12, 12, 65, 36, 87, 18, 79, 14, 73, 70 ])); // 466
14 changes: 14 additions & 0 deletions problem-38.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Say you are given the following array of integer data type.
// Now write a program which will find the biggest integer and print the integer


const solution = (array) => {
let array1 = array.sort(function(a,b){return a - b})
let biggest = array1[array1.length -1];
return biggest;
};

console.log(solution([10, 20, 30, 40, 50])); // 50
console.log(solution([5, 10, 15, 20, 25, 30])); // 30
console.log(solution([44, 665, 221, -434, 643, 123])); // 665
console.log(solution([-34, 64, -1, 0, 45])); // 64