fork download
  1.  
  2. function sortLibrary() {
  3. // var library is defined, use it in your code
  4. // use console.log(library) to output the sorted library data
  5.  
  6. for(var i = 0; i < library.length-1; i++){
  7. for(var j = i+1; j < library.length; j++){
  8. if(library[i].title > library[j].title){
  9. var a = library[i];
  10. library[i] = library[j];
  11. library[j] = a;
  12. }
  13. }
  14. }
  15. console.log(library);
  16. }
  17.  
  18. // tail starts here
  19. var library = [
  20. {
  21. author: 'Bill Gates',
  22. title: 'The Road Ahead',
  23. libraryID: 1254
  24. },
  25. {
  26. author: 'Steve Jobs',
  27. title: 'Walter Isaacson',
  28. libraryID: 4264
  29. },
  30. {
  31. author: 'Suzanne Collins',
  32. title: 'Mockingjay: The Final Book of The Hunger Games',
  33. libraryID: 3245
  34. }
  35. ];
  36.  
  37. sortLibrary();
  38. // your code goes here
Runtime error #stdin #stdout #stderr 0.01s 30384KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:15:4 ReferenceError: console is not defined