JSFiddle - React, Tailwind, and code Playground
by BuddhiP
HTML
<div id="container" />
JavaScript
$(function() {
var source = "/ 07-09-2012 72.60 / 11-09-2012 194.98 / 03-09-2012 94.82 / 04-09-2012 187.56 / 31-10-2012 72 / 18-09-2012 204.75 / 26-09-2012 243.73 / 14-09-2012 86.40 / 20-09-2012 91.63 / 28-09-2012 96.56 / 01-09-2012 94.62 / 17-09-2012 94.86 / 17-09-2012 83.25 / 12-09-2012 94.85 / 18-09-2012 94.86 / 18-09-2012 68.74 / 21-09-2012 94.86 / 21-09-2012 94.86 / 24-09-2012 144.23 / 28-09-2012 92.77 / 30-09-2012 92.77 / 28-09-2012 92.77 / 13-09-2012 151.12 / 03-09-2012 125.80 / 05-09-2012 92.61 / 05-09-2012 95.54 / 12-09-2012 94.59 / 12-09-2012 94.59 / 13-09-2012 125.83 / 18-09-2012 109.38 / 18-10-2012 109.38 / 18-10-2012 109.38 / 18-10-2012 109.38 /";
var month = "09";
var year = "2012";
var calculateSum = function(source, month, year) {
var rexp = new RegExp("/\\s+\\d{2}-" + month + "-" + year + "\\s+(\\d+\\.\\d+)\\s+", "g");
var tot = 0;
var m = rexp.exec(source);
while (m) {
var n = new Number(m[1]);
tot += (n || 0.0)
// This is only for debugging purposes
$("#container").append($('<span>').text(" Found match : " + m[0] + ", Number => " + m[1] + ", Total => " + tot.toString())).append($('<br />'));
m = rexp.exec(source);
}
return tot;
}
var total09 = calculateSum(source, '09', '2012');
$("#container").append($('<br />')).append($('<br />')).append($('<span style="color:green">').text(" Grand Total is : " + total09.toString())).append($('<br />'));
});