Functional Implementation of Bathtub Models

Overview


Basic Setup



let state= {
	orders:20,
	rawMaterials:0,
	finishedProduct:0,
	shippedProduct:0
};
					

Single Step Evolution



function next(state){
	let result = {};
	result.orders = 20;
	result.rawMaterials = state.orders + state.rawMaterials * 0.1;
	result.finishedProduct = state.rawMaterials *0.9;
	result.shippedProduct = state.finishedProduct + state.shippedProduct;
	return result;
}
					

Evolution Over Time



let series = [state];
$range(1,20).forEach(p=>{
	state = next(state);
	series.push(state);
})
					
Try it!