Spaces:
Runtime error
Runtime error
Create check_all_balanced.js
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142
const fs = require('fs');const content = fs.readFileSync('index.js', 'utf8');const lines = content.split('\n');
let stack = [];
for (let i = 0; i < lines.length; i++) { const line = lines[i]; for (let j = 0; j < line.length; j++) { const char = line[j]; if (char === '(') { stack.push({ line: i + 1, char: j + 1, type: '(' }); } else if (char === ')') { if (stack.length > 0 && stack[stack.length - 1].type === '(') { stack.pop(); } else { console.log(`Extra ')' at line ${i + 1}, char ${j + 1}`); } } else if (char === '{') { stack.push({ line: i + 1, char: j + 1, type: '{' }); } else if (char === '}') { if (stack.length > 0 && stack[stack.length - 1].type === '{') { stack.pop(); } else { console.log(`Extra '}' at line ${i + 1}, char ${j + 1}`); } } else if (char === '[') { stack.push({ line: i + 1, char: j + 1, type: '[' }); } else if (char === ']') { if (stack.length > 0 && stack[stack.length - 1].type === '[') { stack.pop(); } else { console.log(`Extra ']' at line ${i + 1}, char ${j + 1}`); } } }}
stack.forEach(item => { console.log(`Unclosed '${item.type}' from line ${item.line}, char ${item.char}`);});check_all_balanced.jsAdded+42