Well, you'd just do it the same way you'd do it with any other language. Namely, you calculate the square of the magnitude of each sample, add these squares all together, divide by the number of samples and then take the square-root of it.
To say it another way, this code computes this value for code running in a web-browser.
function calcRMS(signal)
{
var numSamples = signal.length;
var total = 0;
for (var cur=0; cur<numSamples; cur++)
{
total += signal[cur]*signal[cur];
}
var result = Math.sqrt(total / numSamples);
return result;
}
Since it takes the same energy to pull the microphone-diaphram towards you by a micrometer, as it takes it to push it away from you, a system is needed whereby a sample of -0.5 contributes just as much to the energy computation as a sample of 0.5
By taking the square of each sample, we eliminate the negative sign. This allows us to compute the same value for energy regardless of which direction the microphone is deflected in.
E.g
-2*-2 = 4.
and
2*2 = 4