Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/probmods/webppl into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhlmueller committed Feb 19, 2015
2 parents f149dad + ff1e077 commit 8e64540
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ function copyObj(obj){
return newobj;
}

// more efficient version of (indexOf o map p)
var indexOfPred = function(l,p,start) {
var start = start || 0;
for(var i=start; i<l.length; i++){
if (p(l[i])) return i;
}
return -1
}

// more efficient version of (indexOf o map p o reverse)
var lastIndexOfPred = function(l,p,start) {
var start = start || l.length-1;
for(var i=start; i>=0; i--){
if (p(l[i])) return i;
}
return -1
}

// func(x, i, xs, nextK)
// nextK()
function cpsForEach(func, nextK, xs, i){
Expand Down Expand Up @@ -96,6 +114,8 @@ module.exports = {
cpsForEach: cpsForEach,
gensym: gensym,
logsumexp: logsumexp,
indexOfPred: indexOfPred,
lastIndexOfPred: lastIndexOfPred,
makeGensym: makeGensym,
normalizeArray: normalizeArray,
normalizeHist: normalizeHist,
Expand Down

0 comments on commit 8e64540

Please sign in to comment.