Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr){
- let sum = Number.MIN_SAFE_INTEGER
- let thePart = []
- for(let i = 0; i < arr.length; i++){
- let batch = arr[i]
- let sumNow = 0
- let part = []
- if(batch === 'Bake It!'){
- if(arr.length == 1){
- sum = 0
- }
- break
- }
- else{
- batch = batch.split('#')
- part = [...batch]
- let partition = batch.map(x => Number(x))
- let reducer = (accumulator, currentValue) => accumulator + currentValue;
- sumNow = partition.reduce(reducer)
- }
- if(sumNow > sum){
- sum = sumNow
- thePart = [...part]
- }
- else if(sum == sumNow){
- let ab = sum / thePart.length
- let cd = sum / part.length
- if(ab > cd){
- thePart = [...thePart]
- }
- else if(ab == cd){
- x = thePart.length
- y = part.length
- if(x <= y){
- thePart = [...thePart]
- }
- else{
- thePart = [...part]
- }
- }
- else{
- thePart = [...part]
- }
- }
- }
- console.log(`Best Batch quality: ${sum}`)
- console.log(thePart.join(' '))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement