This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
type Todo = { | |
id: number; | |
title: string; | |
completed: boolean; | |
} | |
type Props = { | |
todo: Todo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let todo: Todo | undefined; | |
for (let i = 0; i < todos.length; i++) { | |
if (todos[i].id === 1) { | |
todo = todos[i]; | |
break; // Remember to break so we don't keep iterating after we found it | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const todo = todos.find((todo) => todo.id === 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const completedAll = todos.every((todo) => todo.completed); | |
console.log(completedAll); // false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let completedAll = true; | |
for (let i = 0; i < todos.length; i++) { | |
if (!todos[i].completed) { | |
completedAll = false; | |
break; | |
} | |
} |
OlderNewer