User talk:MichaelChrisco: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 209: | Line 209: | ||
//global bank array |
//global bank array |
||
var |
var bank = new Array(); |
||
function distribute( beans ){ |
function distribute( beans ){ |
||
Line 219: | Line 219: | ||
// the first number |
// the first number |
||
if ( |
if ( bank.length == 0 ){ |
||
temp = new Array(); |
temp = new Array(); |
||
Line 226: | Line 226: | ||
} |
} |
||
bank = temp; |
|||
}else{ |
}else{ |
||
// if a bean has more rows than our bank, add more rows |
// if a bean has more rows than our bank, add more rows |
||
if ( beans > |
if ( beans > bank.length ){ |
||
//increase array by |
//increase array by bank.length + beans |
||
Line 238: | Line 238: | ||
for(i = 0; i < beans; i++){ |
for(i = 0; i < beans; i++){ |
||
if(i < |
if(i < bank.length){ |
||
temp[i] = |
temp[i] = bank[i]; |
||
}else{ |
}else{ |
||
temp[i] = 0; // start the row with one bean |
temp[i] = 0; // start the row with one bean |
||
Line 246: | Line 246: | ||
// swap the arrays |
// swap the arrays |
||
bank = temp; |
|||
} |
} |
||
Line 255: | Line 255: | ||
// example: 3 would add 1 bean to the first three rows |
// example: 3 would add 1 bean to the first three rows |
||
for(i = 0; i < beans; i++){ |
for(i = 0; i < beans; i++){ |
||
bank[i] = parseInt(bank[i]) + 1; |
|||
} |
} |
||
Line 264: | Line 264: | ||
function beanSort( list ){ |
function beanSort( list ){ |
||
bank = new Array(); // clear list |
|||
for(a = 0; a < list.length; a++){ |
for(a = 0; a < list.length; a++){ |
||
Line 276: | Line 276: | ||
var sample = new Array(1,4,3,10,6); |
var sample = new Array(1,4,3,10,6); |
||
beanSort(sample); // adds sample to bank, stored in |
beanSort(sample); // adds sample to bank, stored in bank |
||
beanSort( |
beanSort(bank); // sorts the bank in the bank |
||
// an alert( |
// an alert(bank) would show the final sorted array |
||
Line 286: | Line 286: | ||
-Jeff Blanchette |
-Jeff Blanchette |
||
== Sorry for missing you in IRC == |
== Sorry for missing you in IRC == |