Skip to content

Commit ff02a3b

Browse files
new tasks
1 parent 5528b75 commit ff02a3b

11 files changed

+447
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
function biggestElement(matrix) {
2+
return maxNumber = matrix
3+
.map(row => Math.max(...row))
4+
.reduce((a, x) => Math.max(a, x), Number.MIN_SAFE_INTEGER);
5+
6+
}
7+
8+
console.log(biggestElement([[20, 50, 10],
9+
[8, 33, 145]]
10+
));
11+
12+
console.log(biggestElement([[3, 5, 7, 12],
13+
[-1, 4, 33, 2],
14+
[8, 3, 0, 4]]
15+
));
16+
17+
18+
// function biggestElement(arrays) {
19+
// let maxNumber = Number.MIN_SAFE_INTEGER;
20+
//
21+
// arrays.forEach(row => {
22+
// let currentMax = Number.MIN_SAFE_INTEGER;
23+
//
24+
// row.forEach(num => {
25+
// if (currentMax < num) {
26+
// currentMax = num;
27+
// }
28+
// });
29+
// if (maxNumber < currentMax) {
30+
// maxNumber = currentMax;
31+
// }
32+
// });
33+
//
34+
// console.log(maxNumber)
35+
// }
36+
//
37+
// biggestElement([[20, 50, 10],
38+
// [8, 33, 145]]
39+
// )
40+
//
41+
// biggestElement([[3, 5, 7, 12],
42+
// [-1, 4, 33, 2],
43+
// [8, 3, 0, 4]]
44+
// )
45+
46+
47+
// function biggestElement(arrays) {
48+
//
49+
// let maxNum = arrays.map((row) => Math.max(...row));
50+
// console.log(maxNum.sort((a, b) => a - b).reverse()[0]);
51+
//
52+
// }
53+
//
54+
// biggestElement([[20, 50, 10],
55+
// [8, 33, 145]]
56+
// )
57+
//
58+
// biggestElement([[3, 5, 7, 12],
59+
// [-1, 4, 33, 2],
60+
// [8, 3, 0, 4]]
61+
// )
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function pieceOfPie(array, start, end) {
2+
3+
let startIndex = array.indexOf(start);
4+
let endIndex = array.indexOf(end) + 1;
5+
return result = array.slice(startIndex, endIndex);
6+
7+
}
8+
9+
console.log(pieceOfPie(['Pumpkin Pie',
10+
'Key Lime Pie',
11+
'Cherry Pie',
12+
'Lemon Meringue Pie',
13+
'Sugar Cream Pie'],
14+
'Key Lime Pie',
15+
'Lemon Meringue Pie'
16+
))
17+
18+
19+
console.log(pieceOfPie(['Apple Crisp',
20+
'Mississippi Mud Pie',
21+
'Pot Pie',
22+
'Steak and Cheese Pie',
23+
'Butter Chicken Pie',
24+
'Smoked Fish Pie'],
25+
'Pot Pie',
26+
'Smoked Fish Pie'
27+
))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function diagonalSums(input) {
2+
3+
let firstDiagonal = 0;
4+
let secondDiagonal = 0;
5+
6+
let firstIndex = 0;
7+
let secondIndex = input[0].length - 1;
8+
9+
input.forEach(array => {
10+
firstDiagonal += array[firstIndex++];
11+
secondDiagonal += array[secondIndex--];
12+
13+
});
14+
15+
return firstDiagonal + ' ' + secondDiagonal;
16+
17+
}
18+
19+
console.log(diagonalSums([[20, 40],
20+
[10, 60]]
21+
));
22+
23+
24+
console.log(diagonalSums([[3, 5, 17],
25+
[-1, 7, 14],
26+
[1, -8, 89]]
27+
))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function equalNeighbors(array) {
2+
3+
let counter = 0;
4+
5+
for (let row = 0; row < array.length - 1; row++) {
6+
for (let col = 1; col < array[row].length; col++) {
7+
8+
if (array[row][col] === array[row + 1][col]) {
9+
counter++;
10+
}
11+
if (array[row][col] === array[row][col - 1]) {
12+
counter++;
13+
}
14+
}
15+
}
16+
17+
for (let index = 0; index < array[array.length - 1].length; index++) {
18+
if (array[array.length - 1][index] === array[array.length - 1][index + 1]) {
19+
counter++;
20+
}
21+
}
22+
23+
for (let index = 0; index < array.length - 1; index++) {
24+
if (array[index][0] === array[index + 1][0]) {
25+
counter++;
26+
}
27+
}
28+
return counter;
29+
30+
}
31+
32+
console.log(equalNeighbors([['2', '3', '4', '7', '0'],
33+
['4', '0', '5', '3', '4'],
34+
['2', '3', '5', '4', '2'],
35+
['9', '8', '7', '5', '4']]
36+
));
37+
38+
39+
console.log(equalNeighbors([['test', 'yes', 'yo', 'ho'],
40+
['well', 'done', 'yo', '6'],
41+
['not', 'done', 'yet', '5']]
42+
));
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function equalNeighbors(matrix) {
2+
let equalElementsCount = getEqualElementsCount(matrix);
3+
4+
console.log(equalElementsCount);
5+
6+
function getEqualElementsCount(matrix) {
7+
let count = 0;
8+
9+
for(let row = 0; row < matrix.length - 1; row++) {
10+
for(let col = 0; col < matrix[row].length; col++) {
11+
let neighborRight = matrix[row][col + 1];
12+
let neighborDown = matrix[row + 1][col];
13+
14+
if (matrix[row][col] === neighborRight) {
15+
count++;
16+
}
17+
if(matrix[row][col] === neighborDown) {
18+
count++;
19+
}
20+
if (row === matrix.length - 2 && neighborDown === matrix[row + 1][col + 1]) {
21+
count++;
22+
}
23+
}
24+
}
25+
26+
return count;
27+
}
28+
}
29+
30+
equalNeighbors([['2', '3', '4', '7', '0'],
31+
['4', '0', '5', '3', '4'],
32+
['2', '3', '5', '4', '2'],
33+
['9', '8', '7', '5', '4']]
34+
);
35+
36+
37+
equalNeighbors([['test', 'yes', 'yo', 'ho'],
38+
['well', 'done', 'yo', '6'],
39+
['not', 'done', 'yet', '5']]
40+
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function equalNeighbors(matrice) {
2+
let count = 0;
3+
for (let i = 0; i < matrice.length; i++) {
4+
for (let j = 0; j < matrice[i].length; j++) {
5+
6+
let current = matrice[i][j];
7+
let next = matrice[i][j + 1];
8+
9+
if (i !== matrice.length - 1) {
10+
let neighbour = matrice[i + 1][j];
11+
if (current === neighbour) {
12+
count++;
13+
}
14+
}
15+
if (current === next) {
16+
count++;
17+
}
18+
}
19+
}
20+
return count;
21+
}
22+
23+
console.log(equalNeighbors([['2', '3', '4', '7', '0'],
24+
['4', '0', '5', '3', '4'],
25+
['2', '3', '5', '4', '2'],
26+
['9', '8', '7', '5', '4']]
27+
));
28+
29+
30+
console.log(equalNeighbors([['test', 'yes', 'yo', 'ho'],
31+
['well', 'done', 'yo', '6'],
32+
['not', 'done', 'yet', '5']]
33+
));
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function equalNeighbors(arr) {
2+
let count = 0;
3+
arr.forEach(x =>
4+
x.reduce((a, v) => {
5+
if (a === v) {
6+
count += 1;
7+
}
8+
return v;
9+
})
10+
)
11+
12+
for (let i = 0; i < arr.length - 1; i++) {
13+
arr[i].forEach((_, j) => {
14+
if (arr[i][j] === arr[i + 1][j]) {
15+
count += 1;
16+
}
17+
})
18+
}
19+
return count;
20+
}
21+
22+
23+
console.log(equalNeighbors([['2', '3', '4', '7', '0'],
24+
['4', '0', '5', '3', '4'],
25+
['2', '3', '5', '4', '2'],
26+
['9', '8', '7', '5', '4']]
27+
));
28+
29+
30+
console.log(equalNeighbors([['test', 'yes', 'yo', 'ho'],
31+
['well', 'done', 'yo', '6'],
32+
['not', 'done', 'yet', '5']]
33+
));
34+
35+
36+
console.log(equalNeighbors([['2', '2', '5', '7', '4'],
37+
['4', '0', '5', '3', '4'],
38+
['2', '5', '5', '4', '2']]
39+
))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
let array = [9, 1, 5, 12, 1];
2+
array.sort((a, b) => b - a);
3+
console.log(array)
4+
5+
let names = ['emo', 'ivan', 'pesho', 'ani'];
6+
names.sort((a, b) => a.localeCompare(b));
7+
console.log(names)
8+
9+
10+
let str = 'pesho';
11+
let res = str.slice(0, 3);
12+
console.log(res)
13+
14+
15+
let num = ['9', '1', '5', '12', '1'];
16+
console.log(num.map(Number).map(x => x + 1))
17+
18+
// let numbers = [9, 1, 5, 12, 1];
19+
// let result = numbers.reduce(sumReducer, 0);
20+
//
21+
// function sumReducer(acc, c) {
22+
// return acc + c;
23+
// }
24+
//
25+
// console.log(sumReducer(numbers))
26+
27+
28+
function test(input) {
29+
let result = input
30+
.filter((x, i) => i % 2 !== 0)
31+
.map(x => x * 2);
32+
33+
return result.reverse().join(' ');
34+
}
35+
36+
console.log(test([10, 15, 20, 25]))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
unshift/push - add an element to the beginning/end of an array
2+
shift/pop - remove and return the first/last element of an array
3+

0 commit comments

Comments
 (0)