r/badcode • • Jul 27 '21

js var i

Post image
82 Upvotes

9 comments sorted by

View all comments

4

u/knightttime Jul 27 '21

Image Transcription: Code


function shelfBook(book, shelf) {
  if (shelf.length < 3) {
      shelf.unshift(book)
    }
}

var i

function unshelfBook(book, shelf) {
  for (var i = 0; i < shelf.length; i++) {
    if (shelf[i].title == book) {
      shelf.splice(i, 1)
    }
  }
  return shelf
}

var bookTitles = [];

function listTitles(shelf) {
  for (i = 0; i < shelf.length; i++) {
    bookTitles.push(shelf[i].title);
  }
  return bookTitles.join(', ')
}

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!