function analyzeCorpus()
{
var textToConvert = document.getElementById('textToConvert').value;
document.getElementById('conversionResults').innerHTML = countPetitionsGranted(textToConvert);
}
function countPetitionsGranted(text)
{
text = text.toUpperCase();
var appeals = text.split("DECIDED:");
// Count total petitions granted.
var results = "Total petitions granted: " + (appeals.length - 1) + "<br />";
// Count yearly and monthly petitions granted.
var appealsByYear = new Array(100);
var appealsByMonth = new Array(13);
for (var i = 0; i < appealsByYear.length; i++)
appealsByYear[i] = 0;
for (var i = 0; i < appealsByMonth.length; i++)
appealsByMonth[i] = 0;
for (var i = 0; i < appeals.length; i++)
{
var granted = appeals[i].split("GRANTED");
if (granted.length == 2)
{
// Split decision into tokens.
var grantedTokens = granted[1].split(/\s+/);
if (grantedTokens.length >= 2)
{
// Split date token into date elements, then extract year and month.
var date = grantedTokens[1].split("/");
if (date.length >= 3)
{
appealsByYear[parseInt(date[2],10)]++;
appealsByMonth[parseInt(date[0],10)]++;
}
}
}
}
for (var i = 0; i < appealsByYear.length; i++)
if (appealsByYear[i] != null && appealsByYear[i] > 0)
results = results.concat("<br />Total petitions granted in 20" + i + ": " + appealsByYear[i]);
results = results.concat("<br />");
for (var i = 0; i < appealsByMonth.length; i++)
if (appealsByMonth[i] != null && appealsByMonth[i] > 0)
results = results.concat("<br />Total petitions granted in month " + i + ": " + appealsByMonth[i]);
return results;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.