kale

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
12 if (!input || input.length === 0) {
13 return [];
14 }
15
16 // Edge Case: Handle input with empty strings
17 const rows = input.length;
18 const cols = input[0] ? input[0].length : 0;
19
20 // Edge Case: Handle rows with inconsistent lengths
21 for (let i = 0; i < rows; i++) {
22 if (input[i].length !== cols) {
23 // Pad shorter rows with spaces
24 input[i] = input[i].padEnd(cols, ' ');
25 }
26 }
27
28 // Edge Case: Handle single cell board
29 if (rows === 1 && cols === 1) {
30 return input[0] === '*' ? ['*'] : [' '];
31 }
32
33 const result = [];
34
35 // Process each cell
36 for (let i = 0; i < rows; i++) {
37 let newRow = '';
38 for (let j = 0; j < cols; j++) {
39 if (input[i][j] === '*') {
40 newRow += '*';
41 } else {
42 // Count adjacent flowers
43 let count = 0;
44
45 // Check all 8 adjacent positions
46 for (let di = -1; di <= 1; di++) {
47 for (let dj = -1; dj <= 1; dj++) {
48 // Skip the cell itself
49 if (di === 0 && dj === 0) continue;
50
51 const ni = i + di;
52 const nj = j + dj;
53
54 // Edge Case: Check bounds
55 if (ni >= 0 && ni < rows && nj >= 0 && nj < cols) {
56 if (input[ni][nj] === '*') {
57 count++;
58 }
59 }
60 }
61 }
62
63 // Edge Case: No adjacent flowers
64 if (count === 0) {
65 newRow += ' ';
66 } else {
67 newRow += count.toString();
68 }
69 }
70 }
71 result.push(newRow);
72 }
73
74 return result;
1275};
76
77// Handled Edge Cases: empty input, input with empty strings, rows with inconsistent lengths, single cell board, out of bounds access, no adjacent flowers
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.