DEV Community

loading...

Discussion on: Daily Challenge #299 - Time to Grille!

Collapse
_bkeren profile image
''

JS


const dec2bin = dec => (dec >>> 0).toString(2);

const Grille = (message, code) => {
  const codeToBinary= dec2bin(code).padStart(message.length, "0")
  return codeToBinary.split("")
    .map((binaryLetter, index) => binaryLetter === "1" ? index : '')
    .filter(String)
    .map(index => message.charAt(index)).join("")
}

Enter fullscreen mode Exit fullscreen mode