Created
January 21, 2022 02:22
-
-
Save johnakhilomen/dac1c0c7338922f2166c2a59f9653a77 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
| const comments = [ | |
| { | |
| "userId": 1, | |
| "id": 1, | |
| "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", | |
| "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" | |
| }, | |
| { | |
| "userId": 1, | |
| "id": 2, | |
| "title": "qui est esse", | |
| "body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla" | |
| }, | |
| { | |
| "userId": 1, | |
| "id": 3, | |
| "title": "ea molestias quasi exercitationem repellat qui ipsa sit aut", | |
| "body": "et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut" | |
| } | |
| ]; | |
| function findbyId(posts, id) | |
| { | |
| return posts.find((post)=>post.id === id) | |
| } | |
| function filterLessThanId(posts, id) | |
| { | |
| return posts.filter((post)=>post.id < id) | |
| } | |
| function getAll(posts) | |
| { | |
| return posts.forEach((post)=>console.log(post) ) | |
| } | |
| console.log(findbyId(comments, 3)) | |
| console.log(filterLessThanId(comments, 3)) | |
| getAll(comments) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment