Skip to content

Commit

Permalink
add len(set) JME function
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Jun 8, 2015
1 parent fa9c21f commit 164cf33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/scripts/jme.js
Expand Up @@ -2486,6 +2486,7 @@ newBuiltin('intersection',[TSet,TSet],TSet,setmath.intersection);
newBuiltin('or',[TSet,TSet],TSet,setmath.union);
newBuiltin('and',[TSet,TSet],TSet,setmath.intersection);
newBuiltin('-',[TSet,TSet],TSet,setmath.minus);
newBuiltin('abs',[TSet],TNum,setmath.size);

newBuiltin('in',['?',TSet],TBool,null,{
evaluate: function(args,scope) {
Expand Down
8 changes: 8 additions & 0 deletions runtime/scripts/math.js
Expand Up @@ -2064,6 +2064,14 @@ var setmath = Numbas.setmath = {
*/
minus: function(a,b) {
return a.filter(function(v){ return !setmath.contains(b,v); });
},

/** Size of a set
* @param {set} set
* @returns {number}
*/
size: function(set) {
return set.length;
}
}

Expand Down

0 comments on commit 164cf33

Please sign in to comment.