Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. // console.log('this is a debug message');
  2.  
  3. function solution(A) {
  4. A.sort(function (a, b){return a-b;});
  5. var res = 1;
  6. var counts = {};
  7.  
  8. for (var i = 0; i < A.length; i++) {
  9. var num = A[i];
  10. counts[num] = counts[num] ? counts[num] + 1 : 1;
  11. }
  12. var ancienV,ancienO,res=1;
  13. for (var value in counts) {
  14. var occ = counts[value];
  15. console.log(value+' '+occ);
  16. //console.log(ancien[obj])
  17. res = Math.max(res,occ)
  18. if((Math.abs(ancienV-value)<=1)){
  19. res = Math.max(res,Math.abs(occ-ancienO))
  20. }
  21. ancienV = value
  22. ancienO = occ
  23. }
  24. //console.log(res)
  25. return res
  26. }
  27.  
  28.  
  29. console.log(
  30. solution(
  31. [2,5,4,7,8,9,15,2]
  32. )
  33. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement