JSFiddle - React, Tailwind, and code Playground

by luka kupunia

JavaScript

function meeting(x, need) {
  if(need === 0) return "Game On"
  const result = [];
  for(let i = 0; i < x.length; i++) {
    if(
      x[i][1] - x[i][0].length >= 0 && 
      need > 0
    ) {
      result.push(x[i][1] - x[i][0].length)
      need -= x[i][1] - x[i][0].length
    }
  }
  console.log(result)
  return result
}
meeting([
  ['XXX', 1],
  ['XXXXXX', 6],
  ['X', 2],
  ['XXXXXX', 8],
  ['X', 3],
  ['XXX', 1]
], 5)