I need to know how to write JavaScript (JS) function that prints the binary logarithm for each number in the input. The input comes as an array of number elements.
Here is what is binary logarithm: https://en.wikipedia.org/wiki/Binary_logarithm Examples: Input: 1024 1048576 256 1 2 Output: 10 20 8 0 1
The output should be printed to the console, on a new line for each number.
Interesting js task! Here's how I solved it:
function binaryLogarithm(input) { for (let x of input) { console.log(Math.log2(x)); } } console.log(binaryLogarithm(["1024", "1048576", "256","1","2"]));
622 questions
979 answers
129 comments
53 users