fix: refactor parsing and also fix NaN
Fixes #10 Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
41c9c05ab2
commit
8c3de42f1f
2 changed files with 31 additions and 41 deletions
|
@ -12,37 +12,33 @@ let rRecorder = new Recorder(
|
|||
let left = new AVLTree();
|
||||
let right = new WAVLTree();
|
||||
|
||||
left.recorder = lRecorder;
|
||||
right.recorder = rRecorder;
|
||||
|
||||
function insertCallback() {
|
||||
let number = document.getElementById("insertInput").value;
|
||||
if (number === "") {
|
||||
function operationCallback(lMethod, rMethod, id) {
|
||||
let number = document.getElementById(id).value;
|
||||
let value = parseInt(number);
|
||||
if (number === "" || isNaN(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let value = parseInt(number);
|
||||
|
||||
left.insert(value);
|
||||
right.insert(value);
|
||||
|
||||
document.getElementById("insertInput").value = "";
|
||||
lMethod(value);
|
||||
rMethod(value);
|
||||
document.getElementById(id).value = "";
|
||||
return false;
|
||||
}
|
||||
|
||||
function insertCallback() {
|
||||
return operationCallback(
|
||||
left.insert.bind(left),
|
||||
right.insert.bind(right),
|
||||
"insertInput"
|
||||
);
|
||||
}
|
||||
|
||||
function deleteCallback() {
|
||||
let number = document.getElementById("deleteInput").value;
|
||||
if (number === "") {
|
||||
return false;
|
||||
}
|
||||
|
||||
let value = parseInt(number);
|
||||
|
||||
left.delete(value);
|
||||
right.delete(value);
|
||||
|
||||
document.getElementById("deleteInput").value = "";
|
||||
return false;
|
||||
return operationCallback(
|
||||
left.delete.bind(left),
|
||||
right.delete.bind(right),
|
||||
"deleteInput"
|
||||
);
|
||||
}
|
||||
|
||||
function switchTree(TreeType, side) {
|
||||
|
|
|
@ -7,30 +7,24 @@ let recorder = new Recorder(
|
|||
let tree = new WAVLTree();
|
||||
tree.recorder = recorder;
|
||||
|
||||
function insertCallback() {
|
||||
let number = document.getElementById("insertInput").value;
|
||||
if (number === "") {
|
||||
function operationCallback(method, id) {
|
||||
let number = document.getElementById(id).value;
|
||||
let value = parseInt(number);
|
||||
if (number === "" || isNaN(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let value = parseInt(number);
|
||||
tree.insert(value);
|
||||
|
||||
document.getElementById("insertInput").value = "";
|
||||
method(value);
|
||||
document.getElementById(id).value = "";
|
||||
return false;
|
||||
}
|
||||
|
||||
function insertCallback() {
|
||||
return operationCallback(tree.insert.bind(tree), "insertInput");
|
||||
}
|
||||
|
||||
function deleteCallback() {
|
||||
let number = document.getElementById("deleteInput").value;
|
||||
if (number === "") {
|
||||
return false;
|
||||
}
|
||||
|
||||
let value = parseInt(number);
|
||||
tree.delete(value);
|
||||
|
||||
document.getElementById("deleteInput").value = "";
|
||||
return false;
|
||||
return operationCallback(tree.delete.bind(tree), "deleteInput");
|
||||
}
|
||||
|
||||
function switchTree(TreeType) {
|
||||
|
|
Loading…
Reference in a new issue