Dangelo-JAN/ToDoList

Do I follow JavaScript best practices?

Closed this issue · 0 comments

Make it DRY

const True = (index) => {
for (let i = 0; i < todoes.length; i += 1) {
if (index === todoes[i].index) {
todoes[i].completed = true;
localStorage.setItem('todoes', JSON.stringify(todoes));
}
}
};
const False = (index) => {
for (let i = 0; i < todoes.length; i += 1) {
if (index === todoes[i].index) {
todoes[i].completed = false;
localStorage.setItem('todoes', JSON.stringify(todoes));
}
}
};

ToDoList/src/todolist.js

Lines 51 to 56 in 59ce198

for (let i = 0; i < todoes.length; i += 1) {
todoes[i].index = i + 1;
}
localStorage.setItem('todoes', JSON.stringify(todoes));
window.location.reload();

Use a filter method

for (let i = 0; i < todoes.length; i += 1) {
if (todoes[i].completed === true) {
todoes.splice(i, 1);
}