Spreadsheets let each cell hold either a literal value or a formula that references other cells. In this question, implement a small Spreadsheet class with that behavior.
This question is intentionally limited:
= and only use +.const sheet = new Spreadsheet();sheet.setCell('A1', 10);sheet.setCell('B1', '=A1 + 5');sheet.getCell('B1'); // 15
Unset cells should behave like 0.
const sheet = new Spreadsheet();sheet.setCell('A1', '=B1 + 3');sheet.getCell('A1'); // 3
Referenced cells can contain formulas too.
const sheet = new Spreadsheet();sheet.setCell('A1', 2);sheet.setCell('B1', '=A1 + 3');sheet.setCell('C1', '=B1 + 4');sheet.getCell('C1'); // 9
new Spreadsheet()Creates a Spreadsheet instance with no cells.
spreadsheet.setCell(cellId, input)Stores a value for cellId.
| Parameter | Type | Description |
|---|---|---|
cellId | string | A cell reference such as A1 or B12. |
input | number | string | Either a number or a formula string beginning with =. |
spreadsheet.getCell(cellId)Returns the evaluated numeric value of cellId.
If cellId has not been set, return 0.
A1 and B12.console.log() 语句将显示在此处。