Skip to content

Instantly share code, notes, and snippets.

@basekays
Created November 21, 2018 21:08
Show Gist options
  • Save basekays/3c79f919f50e9cf52d16c6416ccc9040 to your computer and use it in GitHub Desktop.
Save basekays/3c79f919f50e9cf52d16c6416ccc9040 to your computer and use it in GitHub Desktop.
const Values = function() {
this.values = {};
}
Values.prototype.get_value = function(variable) {
return this.values[variable];
}
Values.prototype.set_value = function(variable, value) {
let newValue = 0;
if (value[0] == '=') {
value = value.slice(1);
value = value.split('+');
for (let i = 0; i < value.length; i++) {
newValue += parseInt(this.get_value(value[i]));
}
this.values[variable] = newValue;
} else {
this.values[variable] = value;
}
}
const newValues = new Values();
newValues.set_value('A1', '1');
newValues.set_value('B1', '2');
newValues.set_value('D1', '24');
newValues.set_value('C1', '=A1+B1+D1');
newValues.get_value('A1');
newValues.get_value('C1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment