April 16th, 2019
var bankBalance = $50000;
var autopilot = {
    thingYouWant: 'autopilot'
    cost: $5000;
}
var fsd = {
    thingYouWant: 'fsd'
    cost: $7000;
}

var otherThingsYouReallyWant = [
    {
        thingYouWant: 'vacation',
        cost: $6000
    }
    ,{
        thingYouWant: 'cottage',
        cost: $120000
    }
    ,{
        thingYouWant: 'boat',
        cost: $20000
    }
    ,{
        thingYouWant: 'trailer',
        cost: $22000
    }    
];

function buy(purchase){
    log(purchase);
    bankBalance -= purchase.cost;
}

if(otherThingsYouReallyWant.length > 0){
    foreach(otherThingsYouReallyWant as nextConsideredPurchase){
        if(bankBalance > nextConsideredPurchase.cost){
            buy(nextConsideredPurchase);
        }
    }    
}

if(bankBalance > autopilot.cost){
    buy(autopilot);
}

if(bankBalance > fsd.cost){
    buy(fsd);
}

Posted In:

ABOUT THE AUTHOR:
Software Developer always striving to be better. Learn from others' mistakes, learn by doing, fail fast, maximize productivity, and really think hard about good defaults. Computer developers have the power to add an entire infinite dimension with a single Int (or maybe BigInt). The least we can do with that power is be creative.