mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-21 12:12:44 +01:00
23 lines
539 B
JavaScript
23 lines
539 B
JavaScript
app.compose(function() {
|
|
var should = app.get('should')
|
|
app.set('calc', {
|
|
|
|
numberOfBits: function (num) {
|
|
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);
|
|
}
|
|
});
|
|
|
|
});
|