Question

JavaScript Write a function named "reverse_kvs" that has a key-value store as a parameter and returns...

JavaScript

Write a function named "reverse_kvs" that has a key-value store as a parameter and returns a new key-value store. Your function should add each key-value pair in the parameter to the new key-value store EXCEPT reversing the key and value. For example, if the key-value "extreme":45 were in the parameter then the returned key-value store should contain the key-value pair 45:"extreme".

Homework Answers

Answer #1

CODE:-

var obj = {"extreme":45,"hi":5}

function convertObject(obj) {

var obj2 = {};

// Get keys from obj

var keys = Object.keys(obj)

// Get values from obj

var values = Object.values(obj)

//Old object

console.log(obj)

for(var i=0;i<keys.length;i++){

// Assigning to new Object

obj2[values[i]] = keys[i]

}

//New Object

console.log(obj2)

}

convertObject(obj);

OUTPUT:-

CODE SCREENSHOT:-

If you have any queries, please ask me...Thank you...If you like the answer, please rate our answer.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JavaScript Write a function named "reverse_kvs" that has a key-value store as a parameter and returns...
JavaScript Write a function named "reverse_kvs" that has a key-value store as a parameter and returns a new key-value store. Your function should add each key-value pair in the parameter to the new key-value store EXCEPT reversing the key and value. For example, if the key-value "extreme":45 were in the parameter then the returned key-value store should contain the key-value pair 45:"extreme". The following code doesn't work: function reverse_kvs(d) { var new_d = {}; for (var k in d) {...
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
C++ Write a function named timesOfLetter that reads an array and returns the number of times...
C++ Write a function named timesOfLetter that reads an array and returns the number of times of each lowercase vowel and each uppercase vowel appear in it using reference parameter. • Write a function named timesOfNumber that reads an array and returns the number of times of each odd number, and each even number appear in it using reference parameter. • Write a function named isChar() that determines the input is alphabetic or not during inputting. • Write a function...
Need HTML and JS code. Write a Javascript function named RandomString(randomStringLength) that returns a string filled...
Need HTML and JS code. Write a Javascript function named RandomString(randomStringLength) that returns a string filled with random characters where the length of the random string is defined by the input parameter. HINT: Use a for-loop, Math.random, and the fact that the alphabet has 26 characters (remembering that we can have both lower-case and upper-case characters in a string). This is what I have: <html> <!-- inputbox.html Jerry Davis --> <!-- Web page that sets the correct letter value. -->...
Write a Racket function named listlen that takes a list as a parameter and evaluates to...
Write a Racket function named listlen that takes a list as a parameter and evaluates to the number of elements in the list. For example (listlen empty) should evaluate to 0 and (listlen '(1 2 3)) should eveluate to 3.
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in...
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in milliseconds. Delay should return a function that, when invoked waits for the specified amount of time before executing. HINT - research setTimeout(); 2.Create a function saveOutput that accepts a function (that will accept one argument), and a string (that will act as a password). saveOutput will then return a function that behaves exactly like the passed-in function, except for when the password string is...
1) Write a function in C that takes in a single integer parameter and returns an...
1) Write a function in C that takes in a single integer parameter and returns an array of factors. The function signature should be : int* get_factors(int number) To make things a little easier, assume that the input (number) will never have more than 100 factors. The returned array should be null-terminated. 2) Write a main() function that asks a user for a number, calls the function above, then prints the results.
Write Java code that attempts to call a method named bootUp() which takes a String parameter...
Write Java code that attempts to call a method named bootUp() which takes a String parameter and returns an integer value. The String parameter should be read from a file named "bootConfig.txt" and is the only value in the file. If a BootUpException is thrown, print the Exception object's message. If a DriverException occurs, call the reboot() method and rethrow the original DriverException object. If any other type of Exception is thrown, print a generic error message to the console....
Write a function called fun which has an object as its parameter and returns the name...
Write a function called fun which has an object as its parameter and returns the name of properties of that object in an array. For instance, if it receives {a:1,b:3}, as its parameter, it should return [a, b], or if it receives {u:4, k:3, h:5}, it should return [u, k, h]. Answer:(penalty regime: 10, 20, ... %)
Write a method named generateHashtag that accepts a Scanner object as its parameter – your program...
Write a method named generateHashtag that accepts a Scanner object as its parameter – your program should continuously read phrase (a line of input - can contain spaces) using the nextLine() method of the Scanner class until the String read in equals “done” (ignoring case). For each phrase entered, your method should print a hashtag (#) followed by the phrase with spaces removed and all letters lowercase.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT