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
/** | |
* Calculate binary form of a given number n. | |
* | |
* Recursive implementation to calculate binary number for a given number. | |
* Algorithm is O(log(N)) on both performance and memory consumption. | |
* | |
* @param {number} n Number in base 10 | |
* | |
* @return {string} Binary representation of given number | |
*/ |
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
/** | |
* Exports function to flatten array of nested arrays into a single level array | |
* @param {Array} array of arrays of integers (any depth) | |
* @return {Array} array of integers (one level) | |
*/ | |
const flatten = arr => arr.reduce( (acc, i) => `${acc + ' ' + i}` ).replace(/,/g, ' ').split(' ').map( i => parseInt(i, 10) ); | |
export default flatten; |