javascript - Getting a stack overflow in this array merge -
i've written short recursive function add blank entries every 30 minutes dataset. far can tell, function should tail-recursive, seems cause stack overflow.
just looking @ it, can't work out i've done wrong. advice welcome.
function mergehelper(memo, merge, latesttime) { var currenttime = moment(latesttime.subtract(30, "minutes")), mergetime = moment(merge[0]), thiselement = [currenttime, 0], actualtime; if (!merge.length) { //base case return memo; } if (mergetime.isafter(currenttime)) { // normal case memo.push(merge.pop); actualtime = mergetime.clone(); } else { // failthrough case memo.push(thiselement); actualtime = currenttime.clone(); } return mergehelper(memo, merge, actualtime); } return mergehelper([], data, initialtime);
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.js"></script>
Comments
Post a Comment