Question

In JavaScript define a function named 'lowInventory' which will be called with a dictionary mapping strings...

In JavaScript define a function named 'lowInventory' which will be called with a dictionary mapping strings to numbers and which returns the number of key-value pairs whose value is lee than or equal to 10.

Example:

lowInventory({'milk':14,'butter':5,'bread':37,'jam':8}) must return 2

lowInventory{{'oil':16,'filter':29,'grease':42,'hydraulic fluid':18}) must return 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1
function lowInventory(dictionary){
    count = 0;
    for (var key in dictionary) {
        if (dictionary.hasOwnProperty(key)) {
            if(dictionary[key]<10)
                count++;
        }
    }
    return count;
}

Output:

\color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
In JavaScript define a function named 'lowInventory' which will be called with a dictionary mapping strings...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python: Write a function named "write_values" that takes a key-value store mapping strings to strings as...

    python: Write a function named "write_values" that takes a key-value store mapping strings to strings as a parameter and writes the values of the input to a file named "persuade.txt" with one element per line. If a file named "persuade.txt" already exists it must be overwritten. The function should not return any value

  • HW13.13. Update a dictionary, following some rules, with another dictionary Define a function below, update_dict_with_rules, which...

    HW13.13. Update a dictionary, following some rules, with another dictionary Define a function below, update_dict_with_rules, which takes two arguments: both are a dictionary of strings (keys) to integers (values). Complete the function such that it updates the first dictionary as follows: • For key-value pairs in both dictionaries, sum them • For key-value pairs in the second dictionary only, insert them into the first • Make no changes to key-value pairs unique to the first dictionary These updates should be...

  • HW13.13. Update a dictionary, following some rules, with another dictionary Define a function below, update_dict_with_rules, which...

    HW13.13. Update a dictionary, following some rules, with another dictionary Define a function below, update_dict_with_rules, which takes two arguments: both are a dictionary of strings (keys) to integers (values). Complete the function such that it updates the first dictionary as follows: • For key-value pairs in both dictionaries, sum them • For key-value pairs in the second dictionary only, insert them into the first • Make no changes to key-value pairs unique to the first dictionary These updates should be...

  • Define a JavaScript function named showScores which has one parameter which is a JSON blob (JSON...

    Define a JavaScript function named showScores which has one parameter which is a JSON blob (JSON encoding). The parameter encodes an object which maps strings to Numbers. This object will have the keys: "total" and "count". Your function should display the parameter's value associated with "total" in a div element whose id is "overall" . It must also display the parameter's value associated with "count" in a div element whose id is "num".

  • Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating...

    Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating point numbers. The function will make an HTTPS GET request to the url "https://fury.cse.buffalo.edu/ps-api/a" with a query string containing the same key-value pairs from the input key-value store. The response from the server will be a JSON string representing an object in the format "{"answer": <Number>}" where <Number> is a floating point Number. Return the value at the key "answer" as a float Recall...

  • python:Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating...

    python:Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating point numbers. The function will make an HTTPS GET request to the url "https://fury.cse.buffalo.edu/ps-api/a" with a query string containing the same key-value pairs from the input key-value store. The response from the server will be a JSON string representing an object in the format "{"answer": }" where is a floating point Number. Return the value at the key "answer" as a float Recall that...

  • Define a JavaScript function named activityScore with one parameter. Assume the function will be called with...

    Define a JavaScript function named activityScore with one parameter. Assume the function will be called with an array of Numbers. Define the function so that it creates an Object. This object should have a key equal to "score", and its paired value should be set to the sum of the array’s entries. Return the JSON blob encoding the Object.

  • create a javascript function named bbqFood that takes in an object and returns an array. The...

    create a javascript function named bbqFood that takes in an object and returns an array. The input object will have strings naming party foods as the key and the numbers of people that each key will feed as its values. return an array containing all of the keys whose values are greater than 10, menaing it will feed more than 10 people. example bbqfood(['taco':15, 'hamburger':6,'pasta':42,'fruit':23}) must return ['taco','pasta','fruit']

  • python Function Name: find_me Parameters: a dictionary of strings mapping to strings ( dict ), person1...

    python Function Name: find_me Parameters: a dictionary of strings mapping to strings ( dict ), person1 ( str), person2 (str) Returns: number of people in between the first and last person ( int ) Description: Given a dictionary and two names, find the number of people in between them. The dictionary maps a person ( key ) to the person ( value ) in front of them in a line. If person2 is the value of the personi key, then...

  • Python 3 Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys)...

    Python 3 Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys) to integers (values) and a list of strings. All of the strings in the list are keys to the dictionary. Complete the function such that it returns the subset of the dictionary defined by the keys in the list of strings. For example, with the dictionary ("puffin": 5, "corgi": 2, "three": 3) and the list ("three", "corgi"), your function should return {"corgi": 2, "three"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT