User talk:MichaelChrisco: Difference between revisions

Content added Content deleted
No edit summary
Line 209: Line 209:


//global bank array
//global bank array
var data = new Array();
var bank = new Array();


function distribute( beans ){
function distribute( beans ){
Line 219: Line 219:
// the first number
// the first number
if ( data.length == 0 ){
if ( bank.length == 0 ){
temp = new Array();
temp = new Array();


Line 226: Line 226:
}
}
data = temp;
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 > data.length ){
if ( beans > bank.length ){
//increase array by data.length + beans
//increase array by bank.length + beans
Line 238: Line 238:
for(i = 0; i < beans; i++){
for(i = 0; i < beans; i++){
if(i < data.length){
if(i < bank.length){
temp[i] = data[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
data = temp;
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++){
data[i] = parseInt(data[i]) + 1;
bank[i] = parseInt(bank[i]) + 1;
}
}


Line 264: Line 264:
function beanSort( list ){
function beanSort( list ){


data = new Array(); // clear 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 data
beanSort(sample); // adds sample to bank, stored in bank


beanSort(data); // sorts the data in the bank
beanSort(bank); // sorts the bank in the bank


// an alert(data) would show the final sorted array
// 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 ==