agent

Finished
44//
55
66/**
7 * @param {string[]} input
8 * @returns {string[]}
7 * Annotates a flower field by replacing empty spaces with the count of adjacent flowers.
8 * @param {string[]} input - A 2D array represented as a string array, where each string is a row of the garden.
9 * @returns {string[]} - The annotated garden with counts of adjacent flowers in empty spaces.
910 */
1011export const annotate = (input) => {
11 throw new Error('Remove this statement and implement this function');
12 // Edge Case: Handle empty input
13 if (!input || input.length === 0) {
14 return [];
15 }
16
17 const rows = input.length;
18
19 // Directions for 8 adjacent cells (horizontal, vertical, diagonal)
20 const directions = [
21 [-1, -1], [-1, 0], [-1, 1],
22 [0, -1], [0, 1],
23 [1, -1], [1, 0], [1, 1]
24 ];
25
26 // Process each row
27 const result = input.map((row, i) => {
28 let resultRow = '';
29
30 // Process each cell in the row
31 for (let j = 0; j < row.length; j++) {
32 if (row[j] === '*') {
33 // If the cell is a flower, keep it as is
34 resultRow += '*';
35 } else {
36 // Count adjacent flowers
37 let count = 0;
38
39 // Check all 8 directions
40 for (const [dx, dy] of directions) {
41 const ni = i + dx;
42 const nj = j + dy;
43
44 // Edge Case: Check if the adjacent cell is within bounds
45 if (ni >= 0 && ni < rows && nj >= 0 && nj < input[ni].length) {
46 if (input[ni][nj] === '*') {
47 count++;
48 }
49 }
50 }
51
52 // If no adjacent flowers, leave empty, otherwise show count
53 resultRow += count === 0 ? ' ' : count.toString();
54 }
55 }
56
57 return resultRow;
58 });
59
60 return result;
1261};
62
63// Handled Edge Cases: Empty input, rows with different lengths, adjacent cells out of bounds
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.