mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-23 21:22:48 +01:00
24 lines
517 B
JavaScript
24 lines
517 B
JavaScript
(function(app, should){
|
|
var calc = {};
|
|
|
|
calc.numberOfBits = function(num) {
|
|
should.bePositiveInteger(num);
|
|
return Math.floor(Math.log(num) / Math.log(2)) + 1;
|
|
};
|
|
|
|
calc.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);
|
|
};
|
|
|
|
app.service('calc', calc);
|
|
|
|
})(window.app, window.should);
|