Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurbinder Singh committed Sep 23, 2023
1 parent 452be30 commit ca5f5fd
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function findInitialUpperBound() {
upperBound = 2 * upperBound;
}
} catch (error) {
console.error(error);
// console.error(error);
console.log("Upper bound found: ", upperBound);
}
return upperBound;
Expand All @@ -65,25 +65,34 @@ function determineLocalStorageSize(upperBound, lowerBound) {

console.log({ lowerBound, upperBound });
} catch (error) {
console.error(error);
// console.error(error);

console.log(i, ": Failed. Updating upper bound.");
upperBound = testBound - 1;
console.log({ lowerBound, upperBound });
}
}
console.info("Size of local storage: ", upperBound);
console.info(`Size of local storage: ${upperBound} characters`);
return upperBound;
}

document.getElementById("test-start")?.addEventListener("click", () => {
clearLocalStorage();
let upperBound = findInitialUpperBound();
let lowerBound = Math.floor(upperBound / 2);

if (upperBound === 1) {
console.error("The initial upper bound was 1. Reload the page.");
document.getElementById(
"result"
).innerText = `Local storage was not cleared properly. Please reload the page.`;
return;
}
determineLocalStorageSize(upperBound, lowerBound);

document.getElementById("result").innerHTML = `Calculating.`;
let result = determineLocalStorageSize(upperBound, lowerBound);

document.getElementById(
"result"
).innerText = `The maximum size of local storage is ${result} characters.`;
clearLocalStorage();
});
console.info("Event handler added");

0 comments on commit ca5f5fd

Please sign in to comment.