Skip to content

Instantly share code, notes, and snippets.

@royletron
Last active January 15, 2018 14:55
Show Gist options
  • Save royletron/dcce2437ce34f542d450f3945618ee66 to your computer and use it in GitHub Desktop.
Save royletron/dcce2437ce34f542d450f3945618ee66 to your computer and use it in GitHub Desktop.
var books = [
{
id: 1,
name: 'Intro to Bash',
description: 'A great book about bash',
copies: 3
},
{
id: 2,
name: 'Fundamentals of Web',
description: 'Get to grips with the fundamentals of web tech',
copies: 1
}
]
function getBook(id) {
for (i = 0; i < books.length; i++) {
if (books[i].id === id) { return books[i]; }
}
return undefined
}
// CASE 1
getBook(2);
// CASE 2
getBook(0);
@royletron
Copy link
Author

What will be the return value in CASE 1 and CASE 2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment