title: Find maximum possible time HH:MM by permuting four given digits
body: <p>I recently took a coding test for a promotion at work. This was one of the tasks I really struggled with and was wondering what is the best way to do this. I used a load of if and if else, not the cleanest solution but got the job done.</p>
  
  <p>The question I was asked was:</p>
  
  <p>Format 4 numbers into a 24-hour time (00:00), finding the maximum (latest) time possible, taking into account that the max hours would be 23 and the max minutes would be 59. If not possible, return NOT POSSIBLE.</p>
  
  <p>So for example: </p>
  
  <p>6, 5, 2, 0 would be 20:56</p>
  
  <p>3, 9, 5, 0 would be 09:53</p>
  
  <p>7, 6, 3, 8 would be NOT POSSIBLE</p>
  
  <p>The example function that had to return the time or string looked like this, A, B, C, D being a different number from the comma-separated list above:</p>
  
  <pre><code>function generate(A, B, C, D) {
      // Your code here
  } 
  </code></pre>
  
  <p>How would people tackle this?</p>