<html>
<head>
<script src="//code.jquery.com/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="http://www.chartjs.org/assets/Chart.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<input id="sample"></input>
<div id="result"></div>
<canvas id="income" width="600" height="400"></canvas>
</body>
</html>
var getOcc = function(stri){
var occs = {};
for (var i=0; i < stri.length; i++) {
var ch = stri.charAt(i);
if(ch != " "){
if (ch in occs)
occs[ch] += 1;
else
occs[ch] = 1;
}
}
//console.log(occs);
var k = Object.keys(occs).sort();
var soccs = {};
k.forEach(function(entr){
soccs[entr] = occs[entr];
});
return soccs;
};
var generateData = function(ob){
var tob = ob;
//console.log(tob);
var bd = {labels: [], datasets: [
{
fillColor : "#48A497",
strokeColor : "#48A4D1",
data : []
}
]};
for (var x in ob){
bd.labels.push(x);
bd.datasets[0].data.push(ob[x]);
}
return bd;
};
var compare = function(a,b) {
if (a.last_nom < b.last_nom)
return -1;
if (a.last_nom > b.last_nom)
return 1;
return 0;
};
var sortBV = function(originalData){
var dataArray = [];
for (var letter in originalData) {
var occ = originalData[letter];
dataArray.push({occ: parseInt(occ), letter: letter});
}
dataArray.sort(function(a, b){
if (a.occ > b.occ) return -1;
if (b.occ > a.occ) return 1;
return 0;
});
return dataArray;
};
var matchEng = function(ob, msg) {
var en = ['E','T','A','O','I','N','S','H','R','D','L','C','U','M','W','F','G','Y','P','B','V','K','J','X','Q','Z'];
var rep = {};
var obs = sortBV(ob);
var i = 0;
obs.forEach(function(x){
rep[x.letter] = en[i];
i+=1;
});
var dmsg = "";
for(var ch in msg){
//console.log(rep[msg[ch]]);
dmsg += rep[msg[ch]];
}
console.log(dmsg);
return 0;
};
$('#sample').keyup(function(){
var income = document.getElementById("income").getContext("2d");
var msg = $('#sample').val().toUpperCase().replace(/ /g, '');
var occ = getOcc(msg);
new Chart(income).Bar(generateData(occ));
matchEng(getOcc($('#sample').val().toUpperCase()), msg);
});
Output
This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account
Dismiss xKeyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |