Adsense

Swap object keys and values

 // Write a function that takes an object as argument

// Somehow, the properties and keys of the object got mixed up

// Swap the Javascript object's key with its values and return the resulting object

function

myFunction ( obj )

{

return 

}




myFunction({z:'a',y:'b',x:'c',w:'d'})
Expected
{a:'z',b:'y',c:'x',d:'w'}
myFunction({2:'a',4:'b',6:'c',8:'d'})
Expected
{a:'2',b:'4',c:'6',d:'8'}
myFunction({a:1,z:24})
Expected
{1:'a',24:'z'}

Multiply all object values by x

 // Write a function that takes an object (a) and a number (b) as arguments

// Multiply all values of 'a' by 'b'

// Return the resulting object

function myFunction( a, b )

{

return 

}




myFunction({a:1,b:2,c:3},3)
Expected
{a:3,b:6,c:9}
myFunction({j:9,i:2,x:3,z:4},10)
Expected
{j:90,i:20,x:30,z:40}
myFunction({w:15,x:22,y:13},6)
Expected
{w:90,x:132,y:78}

Sum object values

 // Write a function that takes an object (a) as argument

// Return the sum of all object values

function myFunction( a ) {

return 

}





myFunction({a:1,b:2,c:3})
Expected
6
myFunction({j:9,i:2,x:3,z:4})
Expected
18
myFunction({w:15,x:22,y:13})
Expected
50

newest questions on wordpress