Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script src="js/jquery-3.1.1.min.js"></script>
- <script>
- $(document).ready(function() {
- var debugCount = 0;
- // PREBUILT FREQ ARRAY, RUNNING THROUGH CODE SHOULD
- // GIVE A BINGE RESULT OF 8,5 OR 8,6 THROUGH LOOPS
- // AND RANDOMIZATION. {"Value":Frequency}
- var freq = {"1":1,"8":3,"5":2,"6":2,"7":1};
- function cleanValue(winner) {
- freq[winner] = 0;
- debugCount++;
- // console.log("clean "+winner);
- }
- function getMaxFreq() {
- if (debugCount == 0) {
- var returnObj = {"value":8, "frequency":3};
- } else if (debugCount == 1) {
- var returnObj = {"value":5, "frequency":3};
- } else if (debugCount == 2) {
- var returnObj = {"value":6, "frequency":2};
- } else if (debugCount == 3){
- var returnObj = {"value":7, "frequency":2};
- } else {
- var returnObj = {"value":2, "frequency":1};
- }
- return returnObj;
- }
- // Create final array
- var bingeResults = [];
- // Max number of results
- var maxResults = 2;
- // Continue looping until array is complete
- while(bingeResults.length < maxResults) {
- // create temp array
- if (tmpAry == null) {
- var tmpAry = [];
- var tmpAryFreq = [];
- }
- // Get the current max value/freq from the freq array
- // DEBUG: TEMPORARY VALUE, SHOULD BE RETURNED MAX-FREQ OBJECT
- var maxTmpObj = getMaxFreq();
- // Continue adding elements into the array until
- // the returned number is less than the current
- // console.log(maxTmpObj.value + "," + maxTmpObj.frequency + " tmpAry lastValue " + tmpAryFreq[tmpAryFreq.length-1]);
- if (tmpAry == "" || tmpAryFreq[tmpAryFreq.length-1] == maxTmpObj.frequency) {
- // console.log("true");
- tmpAry.push(maxTmpObj.value);
- tmpAryFreq.push(maxTmpObj.frequency);
- // Clean value from freq obj
- cleanValue(maxTmpObj.value);
- } else if (tmpAry.length > 1) {
- // If the new value is not in the array, and the array
- // is larger than 1 item, pick a random item from the
- // temp array
- var newValue = tmpAry[Math.floor(Math.random() * tmpAry.length)];
- // console.log("random " + newValue);
- tmpAry = null;
- tmpAryFreq = null;
- } else {
- // If the new value is not already in the array, and
- // the array only holds 1 value, return it
- var newValue = tmpAry[0];
- // console.log("solo " + newValue);
- tmpAry = null;
- tmpAryFreq = null;
- }
- // If a new value is returned, push it to results array
- if (newValue != undefined) {
- bingeResults.push(newValue);
- newValue = null;
- }
- // Otherwise, continue looping
- // DEBUG: FORCE SCRIPT FAIL
- }
- console.log(bingeResults);
- });
- </script>
- </head>
- <body>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement