JSFiddle - React, Tailwind, and code Playground

by Pankaj Kargirwar

JavaScript

const bars = [
  ['a', 'b', 'c', 'd'],
  ['a', 'b', 'c', 'd'],
  ['a', 'b', 'c', 'd'],
];

const i = 0;
let tot = bars.slice(i).reduce((a, c) => a + c.length, 0);
const remaining = 16;
let remainingMax = bars.slice(i).map(n => Math.floor((remaining / tot) * n.length));
console.log(`tot: ${tot}`);
console.log(`remainingMax: ${remainingMax}`);