Last active
January 15, 2018 14:55
-
-
Save royletron/dcce2437ce34f542d450f3945618ee66 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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What will be the return value in
CASE 1
andCASE 2
?