Friv games on 2012-09-28 15:38:33
I want to thank you for clearing this issue. I looked everywhere.
Friv on 2012-07-10 09:08:25
Cool code. Many thanks!
??????? ????? ??? on 2012-03-22 13:51:31
Anyone looking for what’s new, visit the gate Yes
Kevin van Zonneveld on 2008-11-25 17:15:40
@ Brett Zamir: Cool, thx!
Brett Zamir on 2008-11-21 00:03:51
Yeah, you were right, sorry. Here it is to accept associative as well as regular arrays for 'keys': Examples:
$keys = {'a':'foo', 2:5, 3:10, 4:'bar'};
//$keys = ['foo', 5, 10, 'bar'];
function array_fill_keys (keys, value) {
    var retObj={};
    for (var key in keys) {
            retObj[keys[key]] = value;
    }
    return retObj;
}
Sorry for the trouble...
Kevin van Zonneveld on 2008-11-18 12:22:10
@ Brett Zamir: Cool, I've committed it. Will be online shortly. Are you sure by the way, that PHP does not allow associative arrays as 'keys'? Otherwise we will have to change the for-loop to support this.
Brett Zamir on 2008-11-16 10:04:07
Here's one for array_fill_keys() with a sample based on the PHP manual page for array_fill_keys(): $keys = ['foo', 5, 10, 'bar']; $a = array_fill_keys($keys, 'banana');

function array_fill_keys (keys, value) {
    for (var i=0, retObj={}; i < keys.length; i++) {
            retObj[keys[i]] = value;
    }
    return retObj;
}

Kevin van Zonneveld on 2008-01-29 20:48:46
@ _argos: Hey argos, Thanks for your input, I've added everything to the project. If you know any more, feel free to leave another comment any time :)
waldo malqui silva aka _argos on 2008-01-29 17:31:35
Hi Kevin. I have some ports to your project, and I wanna know if you change my real name by _argos, sorry for duplicate one function ( array_fill ) and make one function (array_pad) on that you are working :

var Test1 = 4.2;

var Test2 = -4.2;

var Test3 = 5;

var Test4 = -5;

var Test5 = 'prueba';

console.log ( abs ( Test1 ) );

console.log ( abs ( Test2 ) );

console.log ( abs ( Test3 ) );

console.log ( abs ( Test4 ) );

console.log ( abs ( Test5 ) );


function abs ( mixed_number )  {

  return ( ( !isNaN ( mixed_number ) ) ? ( ( mixed_number < 0 ) ? ( mixed_number * -1 ) : mixed_number ) : 0 );

}

	

var TestA = [ 7,8,9 ];

    

console.log ( array_pad ( TestA, 2, 'a' ) );

console.log ( array_pad ( TestA, 5, 'a' ) );

console.log ( array_pad ( TestA, 5, 2 ) );

console.log ( array_pad ( TestA, -5, 'a' ) );

console.log ( array_pad ( TestA, -5, 2 ) );

	

function array_pad ( input, pad_size, pad_value ) {

  var pad = [];		

  if ( input instanceof Array && !isNaN ( pad_size ) ) {
    var newArray = [];
    var newLength = ( ( pad_size < 0 ) ? ( pad_size * -1 ) : pad_size );

    if ( newLength > input.length ) {
      for ( var i = 0; i < ( newLength - input.length ); i++ ) { newArray [ i ] = pad_value; }

      pad = ( ( pad_size < 0 ) ? newArray.concat ( input ) : input.concat ( newArray ) );

    } else {

      pad = input;

    }

  }

  return pad;

}

	

function array_fill ( start_key, num, val ) {

  var fill = [];



  if ( !isNaN ( start_key ) && !isNaN ( num ) ) {

    for ( var i = start_key; i < (start_key + num ); i++ ) {

      fill [ i ] = val;

    }

  }

		

  return fill;

}

        

console.log ( strlen ( 'alexa' ) );


function strlen  ( str ) {

  return str.length;

}

     

console.log ( implode ( '-', [1,2,3,4,5,6,7,8,9,0] ) );



function implode ( glue, pieces ) {

  return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );      

}