English subtitles

← Lookup Solution - Web Development

Get Embed Code
4 Languages

Showing Revision 11 created 05/25/2016 by Udacity Robot.

  1. Here's my solution to this quiz.
  2. We first add this link
  3. that was passed in as a parameter to our links list.
  4. And then we add it to our index by saying link.id=link
  5. into the global index here.
  6. And let's go ahead and give this function a test.
  7. The first thing we need to do is create a link, so I'll do that now.
  8. So we create a new link, and it's going to have id 50.
  9. And then we needed a user id, a submission time, and number of votes,
  10. which we'll just set to 1 for now.
  11. It needs a title and a URL.
  12. So that should make a link.
  13. And now let's actually call our function add new link L.
  14. And now, let's make sure it works.
  15. So the first thing I want to do is make sure we added it to the list link.
  16. So we're going to say print links negative 1,
  17. Which will print the last element in our list of links.
  18. And that's where this link should be
  19. because we appended it to that list.
  20. I'm also going to print link by id 50.
  21. So these should actually print the same thing
  22. and they should both be our new list--or our new link.
  23. Let's go ahead and give that a shot.
  24. Ta-da! All right, so we've updated our list,
  25. and we've updated our index--pretty cool.
  26. So as you can see, an index is really handy
  27. making reads simpler so you don't have to iterate over the entire list,
  28. but there's a certain maintenance cost to having them
  29. in that you have to keep it up to date when you're updating the rest of your database.
  30. And you can imagine if you had multiple indexes on your table,
  31. which you can,
  32. every time you insert a new element into your table,
  33. you need to update all of these indexes.
  34. Okay, great. Let's move on to another quiz.