Created
May 20, 2021 20:52
-
-
Save aaronmaldonado-dev/b2316a50e69f8898478f1cf766f4e157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getCombinations = (n) => { | |
const arr = []; | |
const maxValue = Math.pow(2, n); | |
for (let i = 0; i < maxValue; i++) { | |
arr.push(i.toString(2).padStart(n, '0')); | |
} | |
return arr.filter(item => { | |
const arrItem = item.split(''); | |
for (let i = 0; i < n - 1; i++) { | |
const sum = parseInt(arrItem[i]) + parseInt(arrItem[i + 1]); | |
if (sum > 1) return false; | |
} | |
return true; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment