awesome

Finished
88 * @returns {string[]}
99 */
1010export const annotate = (input) => {
11 throw new Error('Remove this statement and implement this function');
11 // Edge Case: Handle empty input array
12 if (!input || input.length === 0) {
13 return [];
14 }
15
16 const rows = input.length;
17 const cols = input[0].length;
18 const result = [];
19
20 // Edge Case: Handle rows with different lengths
21 for (let i = 0; i < rows; i++) {
22 if (input[i].length !== cols) {
23 throw new Error('All rows must have the same length');
24 }
25 }
26
27 // Directions for 8 adjacent cells (horizontal, vertical, diagonal)
28 const directions = [
29 [-1, -1], [-1, 0], [-1, 1],
30 [0, -1], [0, 1],
31 [1, -1], [1, 0], [1, 1]
32 ];
33
34 for (let i = 0; i < rows; i++) {
35 let newRow = '';
36 for (let j = 0; j < cols; j++) {
37 if (input[i][j] === '*') {
38 newRow += '*';
39 } else {
40 let count = 0;
41 for (const [dx, dy] of directions) {
42 const ni = i + dx;
43 const nj = j + dy;
44
45 // Edge Case: Check bounds to avoid accessing invalid indices
46 if (ni >= 0 && ni < rows && nj >= 0 && nj < cols) {
47 if (input[ni][nj] === '*') {
48 count++;
49 }
50 }
51 }
52
53 // Edge Case: Only replace empty square with count if count > 0, otherwise leave empty
54 newRow += count > 0 ? count.toString() : ' ';
55 }
56 }
57 result.push(newRow);
58 }
59
60 return result;
1261};
62
63// Handled Edge Cases: Empty input array, rows with different lengths, accessing invalid indices, replacing empty squares correctly
Test NameStatus
handles no rows
Pass
handles no columns
Pass
handles no flowers
Pass
handles garden full of flowers
Pass
handles flower surrounded by spaces
Pass
handles space surrounded by flowers
Pass
handles horizontal line
Pass
handles horizontal line, flowers at edges
Pass
handles vertical line
Pass
handles vertical line, flowers at edges
Pass
handles cross
Pass
handles large garden
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.