Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
hello
<script src="index.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

// Conclusion
function diagonalDifference(array) {

let leftToRightSum = leftToRight(array);
let rightToLeftSum = rightToLeft(array);

if (leftToRightSum > rightToLeftSum) {
return leftToRightSum - rightToLeftSum;
}
else if (rightToLeftSum > leftToRightSum) {
return rightToLeftSum - leftToRightSum;
}

};

// diagonalDifference(array);

// // //

// Get the sum of left to right diagonal
function leftToRight(array) {

let arrayToSum = [];

let i = 0;
while (i < array.length) {
arrayToSum.push(array[0 + i][0 + i])
i++;
}

let sum = arrayToSum.reduce((accumulator, currentValue) => accumulator += currentValue);
return sum;
};
// // //

// Get the sum of right to left diagonal
function rightToLeft(array) {

let arrayToSum = [];

let i = 0;
while (i < array.length) {
arrayToSum.push(array[0 + i][array[0 + i].length - 1 - i])
i++;
}

let sum = arrayToSum.reduce((accumulator, currentValue) => accumulator += currentValue);
return sum;
};
// // //


let array = [
[11, 2, 4],
[4, 5, 6],
[10, 8, -12]
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Diagonal Difference
Given a square matrix, calculate the absolute difference between the sums of its diagonals.
For example, the square matrix is shown below:

1 2 3
4 5 6
9 8 9

- The left-to-right diagonal = `1 + 5 + 9 = 15`.
- The right to left diagonal = `3 + 5 + 9 + 17`.
- Their absolute difference is `|15 - 17| = 2`.


### Function description
Complete the `diagonalDifference` function in the editor.
- `diagonalDifference` takes two dimensional array of integers as parameter.
- Returns the absolute diagonal difference

### Example:
[[11, 2, 4],
[4, 5, 6], => 15
[10, 8, -12]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
hi
<script src="index.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
let whereIsWaldo = function (table) {

for (let i = 0; i < table.length; i++) {

let row = table[i];

for (let j = 0; j < row.length - 1; j++) {

if (row[j] !== row[j+1]) {

if (row[j+1] == row[j+2]) {
let res= [i+1,j+1];
return res;
}

else {
let res= [i+1,j+2];
console.log(res)
return res;
}
}
};
};
};



// whereIsWaldo([
// ["A", "A", "A"],
// ["A", "A", "A"],
// ["A", "B", "A"]
// ])

// whereIsWaldo([
// ["d", "c", "c", "c"],
// ["c", "c", "c", "c"]
// ])

// whereIsWaldo([
// ["P", "O", "O", "O"],
// ["O", "O", "O", "O"],
// ["O", "O", "O", "O"],
// ["O", "O", "O", "O"],
// ["O", "O", "O", "O"],
// ["O", "O", "O", "O"]
// ])

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Where's Waldo?

Return the coordinates ([row, col]) of the element that differs from the rest.

### Notes:

- Rows and columns are 1-indexed (not zero-indexed).
- If you get stuck on a challenge please search it online and try to find resources
- If you are really stuck, please ask your Instructors.


### Examples:

whereIsWaldo([
["A", "A", "A"],
["A", "A", "A"],
["A", "B", "A"]
]) ➞ [3, 2]

whereIsWaldo([
["c", "c", "c", "c"],
["c", "c", "c", "d"]
]) ➞ [2, 4]

whereIsWaldo([
["O", "O", "O", "O"],
["O", "O", "O", "O"],
["O", "O", "O", "O"],
["O", "O", "O", "O"],
["P", "O", "O", "O"],
["O", "O", "O", "O"]
]) ➞ [5, 1]