JSFiddle - React, Tailwind, and code Playground

by Shridhar Baddur

JavaScript

var getDecimalValue = function(arr) {
    let sum = 0, len = arr.length;
    debugger;
    for(let i = 0; i < len; i++) {
    	sum += arr[i] % 2 === 0 ? 0 : 1 * Math.pow(2, len - i - 1);
    }
    /* while(head) {
        sum += head.val % 2 === 0 ? 0 : 1 * Math.pow(2, i);  
        head = head.next;
        i++;
    } */
    return sum
};

let arr= [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0]
console.log(getDecimalValue(arr));
/* expected = 18880 */
/* output = 457 */