Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findMaxNumberOfConsecOnes(dec){
- const countConsecOnes = (acc, x) => [acc[0] < acc[1]
- ? acc[1]
- : acc[0],
- x === "1"
- ? acc[1] + 1
- : 0 ];
- return [...(dec >>> 0).toString(2)]
- .reduce(countConsecOnes, [0,0]);
- }
- function findMaxNumberOfConsecOnes(dec){
- const countConsecOnes = (acc, x) => [acc[0] < acc[1] ? acc[1] : acc[0],
- x === "1" ? acc[1] + 1 : 0 ];
- return [...(dec >>> 0).toString(2)]
- .reduce(countConsecOnes, [0,0]);
- function findMaxNumberOfConsecOnes(dec){
- return [...(dec >>> 0).toString(2)]
- .reduce((acc, x) => {
- const current = x === "1" ? acc[1] + 1 : 0;
- const max = Math.max(acc[0], current);
- return [max, current];
- }, [0,0]);
- }
- function findMaxNumberOfConsecOnes(dec){
- const binStr = (dec >>> 0).toString(2);
- let max = 0, current = 0;
- for (const s of binStr) {
- current = s === "1" ? current + 1 : 0;
- max = Math.max(max, current);
- }
- return max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement