Last active
August 20, 2020 09:15
-
-
Save dei-biz/ff636b4a5d44001a3b184396b2f17288 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| async function getTodosList() { | |
| const response = await fetch('https://jsonplaceholder.typicode.com/todos'); //fetch es await function. Podemos llamarlo con await y esperará aquí | |
| const data = await response.json(); //.json es método async, podemos llamarlo con await y esperará aquí. | |
| return data; //el return lo hará cuando la línea anterior acabe, después de esperar la conversión a json de la response | |
| } | |
| async function countCompletedTodosTitleLength(){ | |
| const todos = await getTodosList(); //Llamamos a getTodosList y esperamos aquí hasta que acabe. | |
| console.log(todos | |
| .filter(todo => todo.completed) | |
| .map(todo => todo.title) | |
| .reduce((acc, title) => acc + title.length, 0) | |
| ); //filtramos los completos, sacamos el título y sumamos sus longitudes. Le pasamos eso a console.log | |
| } | |
| countCompletedTodosTitleLength(); //no devuelve nada. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment