Skip to main content
golfed a byte
Source Link
ETHproductions
  • 50.1k
  • 6
  • 94
  • 240

JavaScript (ES6), 3535 34 bytes

f=n=>n?[...f(n>>=1),n?n%2||!n|n%2||-1:1]:[]

Test snippet

let f=n=>n?[...f(n>>=1),n?n%2||!n|n%2||-1:1]:[];

[25, 47, 1, 3, 1234567].map(x => console.log(x + ":", JSON.stringify(f(x))))

JavaScript (ES6), 35 bytes

f=n=>n?[...f(n>>=1),n?n%2||-1:1]:[]

Test snippet

let f=n=>n?[...f(n>>=1),n?n%2||-1:1]:[];

[25, 47, 1, 3, 1234567].map(x => console.log(x + ":", JSON.stringify(f(x))))

JavaScript (ES6), 35 34 bytes

f=n=>n?[...f(n>>=1),!n|n%2||-1]:[]

Test snippet

let f=n=>n?[...f(n>>=1),!n|n%2||-1]:[];

[25, 47, 1, 3, 1234567].map(x => console.log(x + ":", JSON.stringify(f(x))))

Source Link
ETHproductions
  • 50.1k
  • 6
  • 94
  • 240

JavaScript (ES6), 35 bytes

f=n=>n?[...f(n>>=1),n?n%2||-1:1]:[]

Test snippet

let f=n=>n?[...f(n>>=1),n?n%2||-1:1]:[];

[25, 47, 1, 3, 1234567].map(x => console.log(x + ":", JSON.stringify(f(x))))