JSFiddle - React, Tailwind, and code Playground

by Galo Aragoneses

JavaScript

var dataFake = [3,4,3,1,2];
var data = [2,4,1,5,1,3,1,1,5,2,2,5,4,2,1,2,5,3,2,4,1,3,5,3,1,3,1,3,5,4,1,1,1,1,5,1,2,5,5,5,2,3,4,1,1,1,2,1,4,1,3,2,1,4,3,1,4,1,5,4,5,1,4,1,2,2,3,1,1,1,2,5,1,1,1,2,1,1,2,2,1,4,3,3,1,1,1,2,1,2,5,4,1,4,3,1,5,5,1,3,1,5,1,5,2,4,5,1,2,1,1,5,4,1,1,4,5,3,1,4,5,1,3,2,2,1,1,1,4,5,2,2,5,1,4,5,2,1,1,5,3,1,1,1,3,1,2,3,3,1,4,3,1,2,3,1,4,2,1,2,5,4,2,5,4,1,1,2,1,2,4,3,3,1,1,5,1,1,1,1,1,3,1,4,1,4,1,2,3,5,1,2,5,4,5,4,1,3,1,4,3,1,2,2,2,1,5,1,1,1,3,2,1,3,5,2,1,1,4,4,3,5,3,5,1,4,3,1,3,5,1,3,4,1,2,5,2,1,5,4,3,4,1,3,3,5,1,1,3,5,3,3,4,3,5,5,1,4,1,1,3,5,5,1,5,4,4,1,3,1,1,1,1,3,2,1,2,3,1,5,1,1,1,4,3,1,1,1,1,1,1,1,1,1,2,1,1,2,5,3];

var fishes = data.map(d => {
	return {
  	day: d,
    mutiplicity: 1
  }
});

//console.log(fishes);

for(var dayIndex = 0; dayIndex < 256; dayIndex++) {
  day();
  //console.log("Day " + dayIndex);
}
console.log(fishes);

var totalFishesCount = 0;
const forFishes = (f, i) => {
	totalFishesCount = totalFishesCount + f.mutiplicity
};
fishes.forEach(forFishes)
console.log(totalFishesCount);

function day() {
	var newFishCount = 0;
	fishes = fishes.map((p, i) => {
  	if(p.day > 0) {
    	return {
      	day: p.day - 1,
        mutiplicity: p.mutiplicity
      };
    }
    if(p.day == 0) {    	
    	newFishCount = newFishCount + p.mutiplicity;
      return {
      	day: 6,
        mutiplicity: p.mutiplicity
      };
    }
  });
  if(newFishCount) {
    fishes.push({
      day: 8,
      mutiplicity: newFishCount
    });
  }
}