Skip to content

Instantly share code, notes, and snippets.

@ascott1
Created June 9, 2014 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ascott1/1a2027165d155ca8b190 to your computer and use it in GitHub Desktop.
Save ascott1/1a2027165d155ca8b190 to your computer and use it in GitHub Desktop.
requirebin sketch
require('console-log').show(true);
var loanCalc = require('loan-calc');
// amortization table calculations
// calculate the monthly payment using loan-calc
// calculate the interest paid per payment
// calculate remaining loan balance
// calculate sum of interest payments
var amortizationCalc = function(amount, rate, totalTerm, amortizeTerm) {
var monthlyPayment = loanCalc.paymentCalc({amount: amount, rate:rate, termMonths: totalTerm}),
periodInt = (rate / 12) / 100;
var i = 0,
summedInterest = 0,
summedPrincipal = 0;
while( i < amortizeTerm) {
var monthlyIntPaid = amount * periodInt,
monthlyPrincPaid = monthlyPayment - monthlyIntPaid,
summedInterest = summedInterest + monthlyIntPaid,
summedPrincipal = summedPrincipal + monthlyPrincPaid,
amount = amount - monthlyPrincPaid;
i += 1;
console.log(monthlyIntPaid);
}
return summedInterest;
};
// round numbers to two decimal places
var roundNum = function(num) {
return Math.round(num * 100) / 100;
};
var amortize = function(opts) {
var amortized = amortizationCalc(opts.amount, opts.rate, opts.totalTerm, opts.amortizeTerm);
return roundNum(amortized);
};
console.log(amortize({amount: 180000, rate: 4.25, totalTerm: 360, amortizeTerm: 60}));
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){function EventEmitter(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}module.exports=EventEmitter;EventEmitter.EventEmitter=EventEmitter;EventEmitter.prototype._events=undefined;EventEmitter.prototype._maxListeners=undefined;EventEmitter.defaultMaxListeners=10;EventEmitter.prototype.setMaxListeners=function(n){if(!isNumber(n)||n<0||isNaN(n))throw TypeError("n must be a positive number");this._maxListeners=n;return this};EventEmitter.prototype.emit=function(type){var er,handler,len,args,i,listeners;if(!this._events)this._events={};if(type==="error"){if(!this._events.error||isObject(this._events.error)&&!this._events.error.length){er=arguments[1];if(er instanceof Error){throw er}else{throw TypeError('Uncaught, unspecified "error" event.')}return false}}handler=this._events[type];if(isUndefined(handler))return false;if(isFunction(handler)){switch(arguments.length){case 1:handler.call(this);break;case 2:handler.call(this,arguments[1]);break;case 3:handler.call(this,arguments[1],arguments[2]);break;default:len=arguments.length;args=new Array(len-1);for(i=1;i<len;i++)args[i-1]=arguments[i];handler.apply(this,args)}}else if(isObject(handler)){len=arguments.length;args=new Array(len-1);for(i=1;i<len;i++)args[i-1]=arguments[i];listeners=handler.slice();len=listeners.length;for(i=0;i<len;i++)listeners[i].apply(this,args)}return true};EventEmitter.prototype.addListener=function(type,listener){var m;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events)this._events={};if(this._events.newListener)this.emit("newListener",type,isFunction(listener.listener)?listener.listener:listener);if(!this._events[type])this._events[type]=listener;else if(isObject(this._events[type]))this._events[type].push(listener);else this._events[type]=[this._events[type],listener];if(isObject(this._events[type])&&!this._events[type].warned){var m;if(!isUndefined(this._maxListeners)){m=this._maxListeners}else{m=EventEmitter.defaultMaxListeners}if(m&&m>0&&this._events[type].length>m){this._events[type].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[type].length);console.trace()}}return this};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.once=function(type,listener){if(!isFunction(listener))throw TypeError("listener must be a function");var fired=false;function g(){this.removeListener(type,g);if(!fired){fired=true;listener.apply(this,arguments)}}g.listener=listener;this.on(type,g);return this};EventEmitter.prototype.removeListener=function(type,listener){var list,position,length,i;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events||!this._events[type])return this;list=this._events[type];length=list.length;position=-1;if(list===listener||isFunction(list.listener)&&list.listener===listener){delete this._events[type];if(this._events.removeListener)this.emit("removeListener",type,listener)}else if(isObject(list)){for(i=length;i-->0;){if(list[i]===listener||list[i].listener&&list[i].listener===listener){position=i;break}}if(position<0)return this;if(list.length===1){list.length=0;delete this._events[type]}else{list.splice(position,1)}if(this._events.removeListener)this.emit("removeListener",type,listener)}return this};EventEmitter.prototype.removeAllListeners=function(type){var key,listeners;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[type])delete this._events[type];return this}if(arguments.length===0){for(key in this._events){if(key==="removeListener")continue;this.removeAllListeners(key)}this.removeAllListeners("removeListener");this._events={};return this}listeners=this._events[type];if(isFunction(listeners)){this.removeListener(type,listeners)}else{while(listeners.length)this.removeListener(type,listeners[listeners.length-1])}delete this._events[type];return this};EventEmitter.prototype.listeners=function(type){var ret;if(!this._events||!this._events[type])ret=[];else if(isFunction(this._events[type]))ret=[this._events[type]];else ret=this._events[type].slice();return ret};EventEmitter.listenerCount=function(emitter,type){var ret;if(!emitter._events||!emitter._events[type])ret=0;else if(isFunction(emitter._events[type]))ret=1;else ret=emitter._events[type].length;return ret};function isFunction(arg){return typeof arg==="function"}function isNumber(arg){return typeof arg==="number"}function isObject(arg){return typeof arg==="object"&&arg!==null}function isUndefined(arg){return arg===void 0}},{}],Zgz7mW:[function(require,module,exports){var widget=require("./widget");var o=require("observable");var h=require("hyperscript");if("undefined"===typeof console){globals.console={};console.log=function(){};console.error=function(){}}var emitter=widget({style:{height:"400px",width:"200px","border-bottom":"1px dotted black"}});function wrap(name){var log=console[name];console[name]=function(){var args=[].slice.call(arguments);emitter.write(args);log.apply(console,args)}}wrap("log");wrap("error");window.addEventListener("error",function(err){emitter.write([err.stack])});document.body.appendChild(h("div",{style:{background:"white",border:"1px solid black",position:"fixed",right:"20px",bottom:"20px"}},emitter.element,h("div",o.boolean(emitter.show,">","<"),{onclick:function(){emitter.show(!emitter.show())}},{style:{margin:"10px","min-width":"20px","min-height":"20px","text-align":"center"}})));emitter.show(false);module.exports=emitter},{"./widget":13,hyperscript:4,observable:12}],"console-log":[function(require,module,exports){module.exports=require("Zgz7mW")},{}],4:[function(require,module,exports){var split=require("browser-split");var ClassList=require("class-list");var DataSet=require("data-set");module.exports=h;function h(){var args=[].slice.call(arguments),e=null;function item(l){var r;function parseClass(string){var m=split(string,/([\.#]?[a-zA-Z0-9_-]+)/);forEach(m,function(v){var s=v.substring(1,v.length);if(!v)return;if(!e)e=document.createElement(v);else if(v[0]===".")ClassList(e).add(s);else if(v[0]==="#")e.setAttribute("id",s)})}if(l==null);else if("string"===typeof l){if(!e)parseClass(l);else e.appendChild(r=document.createTextNode(l))}else if("number"===typeof l||"boolean"===typeof l||l instanceof Date||l instanceof RegExp){e.appendChild(r=document.createTextNode(l.toString()))}else if(isArray(l))forEach(l,item);else if(isNode(l))e.appendChild(r=l);else if(l instanceof Text)e.appendChild(r=l);else if("object"===typeof l){for(var k in l){if("function"===typeof l[k]){if(/^on\w+/.test(k)){e.addEventListener?e.addEventListener(k.substring(2),l[k]):e.attachEvent(k,l[k])}else{e[k]=l[k]();l[k](function(v){e[k]=v})}}else if(k==="style"){for(var s in l[k])(function(s,v){if("function"===typeof v){e.style.setProperty(s,v());v(function(val){e.style.setProperty(s,val)})}else e.style.setProperty(s,l[k][s])})(s,l[k][s])}else if(k.substr(0,5)==="data-"){DataSet(e)[k.substr(5)]=l[k]}else{e[k]=l[k]}}}else if("function"===typeof l){var v=l();e.appendChild(r=isNode(v)?v:document.createTextNode(v));l(function(v){if(isNode(v)&&r.parentElement)r.parentElement.replaceChild(v,r),r=v;else r.textContent=v})}return r}while(args.length)item(args.shift());return e}function isNode(el){return el&&el.nodeName&&el.nodeType}function isText(el){return el&&el.nodeName==="#text"&&el.nodeType==3}function forEach(arr,fn){if(arr.forEach)return arr.forEach(fn);for(var i=0;i<arr.length;i++)fn(arr[i],i)}function isArray(arr){return Object.prototype.toString.call(arr)=="[object Array]"}},{"browser-split":5,"class-list":6,"data-set":8}],5:[function(require,module,exports){module.exports=function split(undef){var nativeSplit=String.prototype.split,compliantExecNpcg=/()??/.exec("")[1]===undef,self;self=function(str,separator,limit){if(Object.prototype.toString.call(separator)!=="[object RegExp]"){return nativeSplit.call(str,separator,limit)}var output=[],flags=(separator.ignoreCase?"i":"")+(separator.multiline?"m":"")+(separator.extended?"x":"")+(separator.sticky?"y":""),lastLastIndex=0,separator=new RegExp(separator.source,flags+"g"),separator2,match,lastIndex,lastLength;str+="";if(!compliantExecNpcg){separator2=new RegExp("^"+separator.source+"$(?!\\s)",flags)}limit=limit===undef?-1>>>0:limit>>>0;while(match=separator.exec(str)){lastIndex=match.index+match[0].length;if(lastIndex>lastLastIndex){output.push(str.slice(lastLastIndex,match.index));if(!compliantExecNpcg&&match.length>1){match[0].replace(separator2,function(){for(var i=1;i<arguments.length-2;i++){if(arguments[i]===undef){match[i]=undef}}})}if(match.length>1&&match.index<str.length){Array.prototype.push.apply(output,match.slice(1))}lastLength=match[0].length;lastLastIndex=lastIndex;if(output.length>=limit){break}}if(separator.lastIndex===match.index){separator.lastIndex++}}if(lastLastIndex===str.length){if(lastLength||!separator.test("")){output.push("")}}else{output.push(str.slice(lastLastIndex))}return output.length>limit?output.slice(0,limit):output};return self}()},{}],6:[function(require,module,exports){var indexof=require("indexof");module.exports=ClassList;function ClassList(elem){var cl=elem.classList;if(cl){return cl}var classList={add:add,remove:remove,contains:contains,toggle:toggle,toString:$toString,length:0,item:item};return classList;function add(token){var list=getTokens();if(indexof(list,token)>-1){return}list.push(token);setTokens(list)}function remove(token){var list=getTokens(),index=indexof(list,token);if(index===-1){return}list.splice(index,1);setTokens(list)}function contains(token){return indexof(getTokens(),token)>-1}function toggle(token){if(contains(token)){remove(token);return false}else{add(token);return true}}function $toString(){return elem.className}function item(index){var tokens=getTokens();return tokens[index]||null}function getTokens(){var className=elem.className;return filter(className.split(" "),isTruthy)}function setTokens(list){var length=list.length;elem.className=list.join(" ");classList.length=length;for(var i=0;i<list.length;i++){classList[i]=list[i]}delete list[length]}}function filter(arr,fn){var ret=[];for(var i=0;i<arr.length;i++){if(fn(arr[i]))ret.push(arr[i])}return ret}function isTruthy(value){return!!value}},{indexof:7}],7:[function(require,module,exports){var indexOf=[].indexOf;module.exports=function(arr,obj){if(indexOf)return arr.indexOf(obj);for(var i=0;i<arr.length;++i){if(arr[i]===obj)return i}return-1}},{}],8:[function(require,module,exports){var Weakmap=require("weakmap");var Individual=require("individual");var datasetMap=Individual("__DATA_SET_WEAKMAP",Weakmap());module.exports=DataSet;function DataSet(elem){if(elem.dataset){return elem.dataset}var hash=datasetMap.get(elem);if(!hash){hash=createHash(elem);datasetMap.set(elem,hash)}return hash}function createHash(elem){var attributes=elem.attributes;var hash={};if(attributes===null||attributes===undefined){return hash}for(var i=0;i<attributes.length;i++){var attr=attributes[i];if(attr.name.substr(0,5)!=="data-"){continue}hash[attr.name.substr(5)]=attr.value}return hash}},{individual:9,weakmap:11}],9:[function(require,module,exports){var root=require("global");module.exports=Individual;function Individual(key,value){if(root[key]){return root[key]}Object.defineProperty(root,key,{value:value,configurable:true});return value}},{global:10}],10:[function(require,module,exports){(function(global){if(typeof global!=="undefined"){module.exports=global}else if(typeof window!=="undefined"){module.exports=window}}).call(this,typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],11:[function(require,module,exports){void function(global,undefined_,undefined){var getProps=Object.getOwnPropertyNames,defProp=Object.defineProperty,toSource=Function.prototype.toString,create=Object.create,hasOwn=Object.prototype.hasOwnProperty,funcName=/^\n?function\s?(\w*)?_?\(/;function define(object,key,value){if(typeof key==="function"){value=key;key=nameOf(value).replace(/_$/,"")}return defProp(object,key,{configurable:true,writable:true,value:value})}function nameOf(func){return typeof func!=="function"?"":"name"in func?func.name:toSource.call(func).match(funcName)[1]}var Data=function(){var dataDesc={value:{writable:true,value:undefined}},datalock="return function(k){if(k===s)return l}",uids=create(null),createUID=function(){var key=Math.random().toString(36).slice(2);return key in uids?createUID():uids[key]=key},globalID=createUID(),storage=function(obj){if(hasOwn.call(obj,globalID))return obj[globalID];if(!Object.isExtensible(obj))throw new TypeError("Object must be extensible");var store=create(null);defProp(obj,globalID,{value:store});return store};define(Object,function getOwnPropertyNames(obj){var props=getProps(obj);if(hasOwn.call(obj,globalID))props.splice(props.indexOf(globalID),1);return props});function Data(){var puid=createUID(),secret={};this.unlock=function(obj){var store=storage(obj);if(hasOwn.call(store,puid))return store[puid](secret);var data=create(null,dataDesc);defProp(store,puid,{value:new Function("s","l",datalock)(secret,data)});return data}}define(Data.prototype,function get(o){return this.unlock(o).value});define(Data.prototype,function set(o,v){this.unlock(o).value=v});return Data}();var WM=function(data){var validate=function(key){if(key==null||typeof key!=="object"&&typeof key!=="function")throw new TypeError("Invalid WeakMap key")};var wrap=function(collection,value){var store=data.unlock(collection);if(store.value)throw new TypeError("Object is already a WeakMap");store.value=value};var unwrap=function(collection){var storage=data.unlock(collection).value;if(!storage)throw new TypeError("WeakMap is not generic");return storage};var initialize=function(weakmap,iterable){if(iterable!==null&&typeof iterable==="object"&&typeof iterable.forEach==="function"){iterable.forEach(function(item,i){if(item instanceof Array&&item.length===2)set.call(weakmap,iterable[i][0],iterable[i][1])})}};function WeakMap(iterable){if(this===global||this==null||this===WeakMap.prototype)return new WeakMap(iterable);wrap(this,new Data);initialize(this,iterable)}function get(key){validate(key);var value=unwrap(this).get(key);return value===undefined_?undefined:value}function set(key,value){validate(key);unwrap(this).set(key,value===undefined?undefined_:value)}function has(key){validate(key);return unwrap(this).get(key)!==undefined}function delete_(key){validate(key);var data=unwrap(this),had=data.get(key)!==undefined;data.set(key,undefined);return had}function toString(){unwrap(this);return"[object WeakMap]"}try{var src=("return "+delete_).replace("e_","\\u0065"),del=new Function("unwrap","validate",src)(unwrap,validate)}catch(e){var del=delete_}var src=(""+Object).split("Object");var stringifier=function toString(){return src[0]+nameOf(this)+src[1]};define(stringifier,stringifier);var prep={__proto__:[]}instanceof Array?function(f){f.__proto__=stringifier}:function(f){define(f,stringifier)};prep(WeakMap);[toString,get,set,has,del].forEach(function(method){define(WeakMap.prototype,method);prep(method)});return WeakMap}(new Data);var defaultCreator=Object.create?function(){return Object.create(null)}:function(){return{}};function createStorage(creator){var weakmap=new WM;creator||(creator=defaultCreator);function storage(object,value){if(value||arguments.length===2){weakmap.set(object,value)}else{value=weakmap.get(object);if(value===undefined){value=creator(object);weakmap.set(object,value)}}return value}return storage}if(typeof module!=="undefined"){module.exports=WM}else if(typeof exports!=="undefined"){exports.WeakMap=WM}else if(!("WeakMap"in global)){global.WeakMap=WM}WM.createStorage=createStorage;if(global.WeakMap)global.WeakMap.createStorage=createStorage}((0,eval)("this"))},{}],12:[function(require,module,exports){(function(){function bind1(a,b){a(b());b(a)}function bind2(a,b){b(a());a(b);b(a)}function isGet(val){return undefined===val}function isSet(val){return"function"!==typeof val}function all(ary,val){for(var k in ary)ary[k](val)}function remove(ary,item){delete ary[ary.indexOf(item)]}function on(emitter,event,listener){(emitter.on||emitter.addEventListener).call(emitter,event,listener,false)}function off(emitter,event,listener){(emitter.removeListener||emitter.removeEventListener||emitter.off).call(emitter,event,listener,false)}function value(){var _val,listeners=[];return function(val){return isGet(val)?_val:isSet(val)?all(listeners,_val=val):(listeners.push(val),function(){remove(listeners,val)})}}function property(model,key){return function(val){return isGet(val)?model.get(key):isSet(val)?model.set(key,val):(on(model,"change:"+key,val),function(){off(model,"change:"+key,val)})}}function transform(observable,down,up){if("function"!==typeof observable)throw new Error("transform expects an observable");return function(val){return isGet(val)?down(observable()):isSet(val)?observable((up||down)(val)):observable(function(_val){val(down(_val))})}}function not(observable){return transform(observable,function(v){return!v})}function listen(element,event,attr,listener){function onEvent(){listener("function"===typeof attr?attr():element[attr])}on(element,event,onEvent);return function(){off(element,event,onEvent)}}function attribute(element,attr,event){attr=attr||"value";event=event||"input";return function(val){return isGet(val)?element[attr]:isSet(val)?element[attr]=val:listen(element,event,attr,val)}}function select(element){function _attr(){return element[element.selectedIndex].value}function _set(val){for(var i=0;i<element.options.length;i++){if(element.options[i].value==val)element.selectedIndex=i}}return function(val){return isGet(val)?element.options[element.selectedIndex].value:isSet(val)?_set(val):listen(element,"change",_attr,val)}}function toggle(el,up,down){var i=false;return function(val){function onUp(){i||val(i=true)}function onDown(){i&&val(i=false)}return isGet(val)?i:isSet(val)?undefined:(on(el,up,onUp),on(el,down||up,onDown),function(){off(el,up,onUp);off(el,down||up,onDown)})}}function error(message){throw new Error(message)}function compute(observables,compute){function getAll(){return compute.apply(null,observables.map(function(e){return e()}))}return function(val){return isGet(val)?getAll():isSet(val)?error("read-only"):observables.forEach(function(obs){obs(function(){val(getAll())})})}}function boolean(observable,truthy,falsey){return transform(observable,function(val){return val?truthy:falsey},function(val){return val==truthy?true:false})}var exports=value;exports.bind1=bind1;exports.bind2=bind2;exports.value=value;exports.not=not;exports.property=property;exports.input=exports.attribute=attribute;exports.select=select;exports.compute=compute;exports.transform=transform;exports.boolean=boolean;exports.toggle=toggle;exports.hover=function(e){return toggle(e,"mouseover","mouseout")};exports.focus=function(e){return toggle(e,"focus","blur")};if("object"===typeof module)module.exports=exports;else this.observable=exports})()},{}],13:[function(require,module,exports){var EventEmitter=require("events").EventEmitter;var h=require("hyperscript");var o=require("observable");var log=console.log;module.exports=function(opts){opts=opts||{};var emitter=new EventEmitter;var follow=true;opts.max=1e4;opts.margin=opts.margin||30;opts.style=opts.style||{height:"100%",width:"50%"};opts.template=opts.template||function(args){return h("pre",args.map(function(e,i){if(!i)return String(e);try{return JSON.stringify(e,false,2)}catch(e){return String(e)}}).join(" "))};emitter.show=o();var inner=h("div");var logger=h("div",{style:opts.style},{style:{overflow:"scroll",display:o.boolean(emitter.show,"block","none")}},inner);emitter.follow=function(){var el=inner.lastElementChild;el&&el.scrollIntoViewIfNeeded();follow=true};emitter.show(function(v){if(v&&follow)emitter.follow()});emitter.show(true);emitter.end=function(){};emitter.writable=true;emitter.log=emitter.write=function(data){var message=opts.template(data);var bottom=inner.getBoundingClientRect().bottom;var size=logger.getBoundingClientRect().bottom;follow=bottom<size+opts.margin;inner.appendChild(message);if(follow&&emitter.show()){while(inner.clientHeight>opts.max&&inner.children.length){inner.removeChild(inner.firstChild)}message.scrollIntoViewIfNeeded()}return true};emitter.element=logger;return emitter}},{events:1,hyperscript:4,observable:12}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({VJBKrZ:[function(require,module,exports){"use strict";var paymentCalc=function(loanAmt,loanRate,loanTerm){var monthlyRate=loanRate/100/12;return loanAmt*(monthlyRate/(1-Math.pow(1+monthlyRate,-loanTerm)))};var roundNum=function(num){return Math.round(num*100)/100};var cleanOpts=function(opts){if(isNaN(opts.amount)){opts.amount=parseFloat(opts.amount.replace(/[^0-9\.]+/g,""))}if(typeof opts.amount==="undefined"||isNaN(parseFloat(opts.amount))||opts.amount<=0){throw new Error("Please specify a loan amount as a positive number")}if(typeof opts.rate==="undefined"||isNaN(parseFloat(opts.rate))||opts.rate<0){throw new Error("Please specify a loan rate as a number")}if(typeof opts.termMonths==="undefined"||isNaN(parseFloat(opts.termMonths))||opts.termMonths<=0){throw new Error("Please specify the length of the term as a positive number")}return{amount:opts.amount,rate:opts.rate,termMonths:opts.termMonths||360}};exports.paymentCalc=function(opts){opts=cleanOpts(opts);var monthlyPayment=paymentCalc(opts.amount,opts.rate,opts.termMonths);return roundNum(monthlyPayment)};exports.totalInterest=function(opts){opts=cleanOpts(opts);var monthlyPayment=paymentCalc(opts.amount,opts.rate,opts.termMonths);var rawInterest=monthlyPayment*opts.termMonths-opts.amount;return roundNum(rawInterest)}},{}],"loan-calc":[function(require,module,exports){module.exports=require("VJBKrZ")},{}]},{},[]);require("console-log").show(true);var loanCalc=require("loan-calc");var amortizationCalc=function(amount,rate,totalTerm,amortizeTerm){var monthlyPayment=loanCalc.paymentCalc({amount:amount,rate:rate,termMonths:totalTerm}),periodInt=rate/12/100;var i=0,summedInterest=0,summedPrincipal=0;while(i<amortizeTerm){var monthlyIntPaid=amount*periodInt,monthlyPrincPaid=monthlyPayment-monthlyIntPaid,summedInterest=summedInterest+monthlyIntPaid,summedPrincipal=summedPrincipal+monthlyPrincPaid,amount=amount-monthlyPrincPaid;i+=1;console.log(monthlyIntPaid)}return summedInterest};var roundNum=function(num){return Math.round(num*100)/100};var amortize=function(opts){var amortized=amortizationCalc(opts.amount,opts.rate,opts.totalTerm,opts.amortizeTerm);return roundNum(amortized)};console.log(amortize({amount:18e4,rate:4.25,totalTerm:360,amortizeTerm:60}));
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"console-log": "1.0.0",
"loan-calc": "0.2.1"
}
}
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment