Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, December 10, 2016

Codefights arrayPacking


//sample solution
//pad function courtesy of stack overflow
function pad(n, width, z) {
  z = z || '0';
  n = n + '';
  return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}

function arrayPacking(a) {
    var someString=""
    for(i=0; i<a.length; i++){
        someString = pad((a[i] >>> 0).toString(2),8) + someString;
    }
    return parseInt(someString,2);
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts