Skip to content

5 Bugs & Performance

Aashir Sohail edited this page Aug 12, 2020 · 5 revisions

Bugs

1. index.html - line 16 the missing id tag was preventing the toggle all button to fail.

Bug:

<input class="toggle-all" type="checkbox">

Fix:

<input id="toggle-all" class="toggle-all" type="checkbox">


2. controller.js -ine 96 The spelling mistake prevented from the new to-do to being added.

Bug:

Controller.prototype.adddItem

Fix:

Controller.prototype.addItem


3. store.js - line 87 The new added was assigned before being checked whether its already presnt or not.

Bug:

for (var i = 0; i < 6; i++) {
   newId += charset.charAt(Math.floor(Math.random() * charset.length));
}

Fix:

var repeat = true;
while (repeat) {
   for (var i = 0; i < 6; i++) {
     newId += charset.charAt(Math.floor(Math.random() * charset.length));
   }
   repeat = false;
   todos.forEach( todo => {
     if(todo.id === newId) repeat = true;
   }); 
}

Performance

store.js - line 127

Issue: Double for loop that iterates the to-dos to get the id, then another loop iterates to split/remove that to-do

for (var i = 0; i < todos.length; i++) {
    if (todos[i].id == id) {
        todoId = todos[i].id;
    }
}
for (var i = 0; i < todos.length; i++) {
    if (todos[i].id == todoId) {
        todos.splice(i, 1);
    }
}

Fix

for (var i = 0; i < todos.length; i++) {
    if (todos[i].id == id) {
        todos.splice(i, 1);
    }
}