Skip to content

Commit

Permalink
Merge pull request #32 from Vindexus/count-options
Browse files Browse the repository at this point in the history
Show total number of options in bottom right.
  • Loading branch information
soulwire committed Dec 6, 2016
2 parents 4580a8f + 60ec4d9 commit 0bc8890
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ <h1>What The Fuck Is&hellip;</h1>
<footer>
<div id="about">If you make it, make sure you make it <a href="http://www.opensource.org/" target="blank">Open Source</a></div>
<div id="credit">Built with <a href="https://github.com/soulwire/WTFEngine" title="An HTML / CSS / JavaScript template for creating WhatTheFuckIsMyMashup.com style web sites" target="_blank">WTF Engine</a> by <a href="http://blog.soulwire.co.uk/" title="Made by Justin Windle @soulwire">Justin</a></div>
<div>Inspired by <a href="http://whatthefuckshouldimakefordinner.com/" target="_blank">WTFSIMFD<a/></div>
<div>Inspired by <a href="http://whatthefuckshouldimakefordinner.com/" target="_blank">WTFSIMFD</a></div>
<div id="total">There are <span id="templates"></span> and <span id="outcomes"></span> possibilities</div>
</footer>
<img class="loading" src="images/loading.gif">
</div>
Expand Down
30 changes: 30 additions & 0 deletions scripts/wtf.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,36 @@ var WTF = (function() {
initUI();
buildRexExp();
generate();
$('#templates').html(templates.length + ' template' + (templates.length == 1 ? '' : 's'))
$('#outcomes').html(getTotalNumOptions().toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","))
}

function getTotalNumOptions() {
var num = 0
for(var i = 0; i < templates.length; i++) {
num += getNumTemplateOptions(templates[i])
}
return num
}

function getNumTemplateOptions( template ) {
var type, iter = 0, // Safety mechanism
item = regex.exec( template ),
copy = cloneCorpus();

var num = 0
while ( item && ++iter < 1000 ) {
type = item[ 0 ].substr(1);
var typeNum = corpus[type].length
if(num == 0) {
num = corpus[type].length
}
else {
num = num * corpus[type].length
}
item = regex.exec( template );
}
return num
}

/*
Expand Down

0 comments on commit 0bc8890

Please sign in to comment.