Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

Second-Cheapest Book

Allowed Time: 40 mins

Given an array of book objects, return the book object with the second-cheapest price. eg.

    {title:'Fox In Socks', price:32.20},
    {title:'The Cat In The Hat', price:16.20},
    {title:'Green Eggs and Ham', price:28.50},
    {title:'Thinking Fast and Slow', price:58.80}

should return the third object in the input list.


  • If the array is empty, return undefined
  • If there is only one item in the array, return that item
  • All books will have a different price
  • Do not sort the list
  • The return value must point to an object in the original list, not a copy of that object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment