JSFiddle - React, Tailwind, and code Playground

by Francisco Presencia Fandos

HTML

<script src="https://cdn.jsdelivr.net/npm/uwork@1/uwork.js"></script>

JavaScript

// Create the piece of work to be performed
const work = uwork((number = 10000) => {
  let inside = 0;
  for (var i = 0; i < number; i++) {
    let x = Math.random(), y = Math.random();
    if (x * x + y * y <= 1) inside++;
  }
  return 4 * inside / number;
});

Promise.all([work(1000), work(1000), work(1000), work(1000)]).then(all => {
	const total = all.reduce((total, val, i, arr) => total + val / arr.length, 0);
	alert('Pi ≈ ' + total.toFixed(5));
});