mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-11 07:22:19 +01:00
30 lines
719 B
JavaScript
30 lines
719 B
JavaScript
app.set('calc', function() {
|
|
"use strict";
|
|
|
|
var should = app.get('should');
|
|
return {
|
|
|
|
numberOfBits: function (num) {
|
|
if(num < 0) {
|
|
return 32;
|
|
}
|
|
should.bePositiveInteger(num);
|
|
return Math.floor(Math.log(num) / Math.log(2)) + 1;
|
|
},
|
|
|
|
maxNumberOfBits: function (arr) {
|
|
|
|
var counts = [], num;
|
|
for (var i = 0; i < arr.length; i++) {
|
|
num = arr[i];
|
|
counts.push(this.numberOfBits(num));
|
|
}
|
|
|
|
return Math.max.apply(null, counts);
|
|
},
|
|
|
|
calcExpression: function (expr) {
|
|
return eval(expr.expressionString);
|
|
}
|
|
}
|
|
}); |