Title: #3484 - Design Spreadsheet - LeetCode JavaScript Solutions
Open Graph Title: #3484 - Design Spreadsheet - LeetCode JavaScript Solutions
X Title: #3484 - Design Spreadsheet - LeetCode JavaScript Solutions
Description: A spreadsheet is a grid with 26 columns (labeled from 'A' to 'Z') and a given number of rows. Each cell in the spreadshe...
Open Graph Description: A spreadsheet is a grid with 26 columns (labeled from 'A' to 'Z') and a given number of rows. Each cell in the spreadshe...
X Description: A spreadsheet is a grid with 26 columns (labeled from 'A' to 'Z') and a given number of rows. Each cell in the spreadshe...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/design-spreadsheet
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/design-spreadsheet","name":"#3484 - Design Spreadsheet - LeetCode JavaScript Solutions","description":"A spreadsheet is a grid with 26 columns (labeled from 'A' to 'Z') and a given number of rows. Each cell in the spreadshe...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number} rows\n */\nvar Spreadsheet = function(rows) {\n this.cellValues = new Map();\n this.totalRows = rows;\n};\n\n/**\n * @param {string} cell\n * @param {number} value\n * @return {void}\n */\nSpreadsheet.prototype.setCell = function(cell, value) {\n this.cellValues.set(cell, value);\n};\n\n/**\n * @param {string} cell\n * @return {void}\n */\nSpreadsheet.prototype.resetCell = function(cell) {\n this.cellValues.delete(cell);\n};\n\n/**\n * @param {string} formula\n * @return {number}\n */\nSpreadsheet.prototype.getValue = function(formula) {\n const expression = formula.slice(1);\n const operands = expression.split('+');\n\n const leftValue = this.parseOperand(operands[0]);\n const rightValue = this.parseOperand(operands[1]);\n\n return leftValue + rightValue;\n};\n\n/**\n * @param {string} operand\n * @return {number}\n */\nSpreadsheet.prototype.parseOperand = function(operand) {\n if (/^\\d+$/.test(operand)) {\n return parseInt(operand);\n }\n return this.cellValues.get(operand) || 0;\n};","keywords":"LeetCode 3484, #3484 - Design Spreadsheet, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/design-spreadsheet |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/design-spreadsheet/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/3484-design-spreadsheet.js |
| Array | https://leetcodejavascript.com/tags/array |
| String | https://leetcodejavascript.com/tags/string |
| Hash Table | https://leetcodejavascript.com/tags/hash-table |
| Matrix | https://leetcodejavascript.com/tags/matrix |
| Design | https://leetcodejavascript.com/tags/design |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow