Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. function solve(arr){
  2. let sum = Number.MIN_SAFE_INTEGER
  3. let thePart = []
  4. for(let i = 0; i < arr.length; i++){
  5. let batch = arr[i]
  6. let sumNow = 0
  7. let part = []
  8. if(batch === 'Bake It!'){
  9. if(arr.length == 1){
  10. sum = 0
  11. }
  12. break
  13. }
  14. else{
  15. batch = batch.split('#')
  16. part = [...batch]
  17. let partition = batch.map(x => Number(x))
  18. let reducer = (accumulator, currentValue) => accumulator + currentValue;
  19. sumNow = partition.reduce(reducer)
  20. }
  21. if(sumNow > sum){
  22. sum = sumNow
  23. thePart = [...part]
  24. }
  25. else if(sum == sumNow){
  26. let ab = sum / thePart.length
  27. let cd = sum / part.length
  28. if(ab > cd){
  29. thePart = [...thePart]
  30. }
  31. else if(ab == cd){
  32. x = thePart.length
  33. y = part.length
  34. if(x <= y){
  35. thePart = [...thePart]
  36. }
  37. else{
  38. thePart = [...part]
  39. }
  40. }
  41. else{
  42. thePart = [...part]
  43. }
  44. }
  45. }
  46. console.log(`Best Batch quality: ${sum}`)
  47. console.log(thePart.join(' '))
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement