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 cf3ab04

Browse files
Add ZeroLocator problem to Pramp/finished
1 parent c3cadc2 commit cf3ab04

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎Pramp/Completed/ZeroLocator.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
let arr = [
2+
[1, 1, 1, 1, 1, 1, 1],
3+
[1, 1, 1, 1, 0, 0, 1],
4+
[1, 1, 1, 1, 0, 0, 1],
5+
[1, 1, 1, 1, 0, 0, 1],
6+
[1, 1, 1, 1, 1, 1, 1]
7+
];
8+
9+
function zeroLocator(array) {
10+
let topLeft = [];
11+
let bottomRight = [];
12+
13+
for (let i = 0; i < array.length; i++) {
14+
for (let j = 0; j < array[i].length; j++) {
15+
if (array[i][j] === 0) {
16+
if (topLeft.length === 0) {
17+
topLeft = [i, j];
18+
}
19+
bottomRight = [i, j];
20+
}
21+
}
22+
}
23+
console.log(topLeft, bottomRight);
24+
return [topLeft, bottomRight];
25+
}
26+
27+
zeroLocator(arr);

0 commit comments

Comments
(0)

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