title: Sorting with constraint no consecutive equals
body: <p>I would like to sort a news feed according to created date, which is trivial, but I don't want 2 consecutive posts with the same userId field.</p>
  
  <p>This might not be theoritically possible because what if I have only 2 posts with the same userId field?</p>
  
  <p>I am looking for an algorithm that sorts according to fieldA but doesn't have 2 consecutive elements with the same fieldB.</p>
  
  <p>It would also nice to have a parametrized algorithm about the required number of different posts between same user's different posts. (In the first scenario this parameter is 1)</p>
  
  <p>I'm not looking for performance (O(n^2) would be okay) but a clever &amp; simple way, maybe with 5 lines of code.</p>
  
  <p>Language doesn't matter but Javascript is preferred.</p>