Question

In: Computer Science

JavaScript each item must have at least three categorical attributes and at least one numeric attribute....

JavaScript

each item must have at least three categorical attributes and at least one numeric attribute.

Write a function that counts the number of values each item attribute has. This is effectively a group-by on the item table for each column. For example: if the first attribute is colour, and its values are [ ‘red’, ‘black’, ‘white’, ‘black’, ‘red’ ],

the counts for colour would be: red 2 black 2 white 1

Solutions

Expert Solution

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript GroupBy</h2>

<script>

var items = {color: ['red', 'red', 'white', 'black', 'white'], style: ['long', 'long', 'short', 'short', 'medium', 'long'], size: [6, 8, 10, 12, 6, 12, 10]}


function groupBy(items) {
    var result = {}
    for (var prop in items) {
      var r = {}
      var arr = items[prop]
      for(var i=0; i<arr.length; i++) {
          if(arr[i] in r) {
                  r[arr[i]] += 1;
          } else {
                  r[arr[i]] = 1;
          }
      }
      result[prop] = r
      }
        
    return result
}

console.log(groupBy(items))
</script>

</body>
</html> 
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

function groupBy(arr) { var result = { for(var i=0; i<arr.length; i++) { if(colors[i] in result) { result[colors[i]] += 1; } else { result[colors[i]] = 1; return result console.log(groupBy (colors) </scrint> o Elements Console Sources Network Performanc Do top - url:https://distantsupportives {red: 2, black: 2, white: 1}


Related Solutions

Your faceted search item will have at least one categorical attribute. For example a clothing store item could have an attribute called colour, its values could be red, white, black etc.
(a) Define a class for your item including a constructor.(b) Write a function that loads csv text(the function up to you) then creates an array of items using the above class’s constructor.(c) Add a print method to your class. Write test code that prints your item array using this method.Your faceted search item will have at least one categorical attribute. For example a clothing store item could have an attribute called colour, its values could be red, white, black etc.Your...
1 For each of the following variables, identify the type of variable (numeric or categorical) and...
1 For each of the following variables, identify the type of variable (numeric or categorical) and level of measurement (nominal, ordinal, interval, or ratio). a. Business size (micro, small, medium, large) b. Airplane ticket price 2 Consider the following sample of data: 1.2 28.4 32.6 17.0 13.5 2.2 38.0 41.4 1.9 14.4 21.8 23.8 a. Calculate the quartiles. b. Calculate the average c. Calculate the standard deviation. 3  Given the following five-number summary, are there any outliers in the data? Min:...
A. Create a Dollar currency class with two integer attributes and one string attribute, all of...
A. Create a Dollar currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. The string attribute will represent the currency name. B. Create a CIS22C Dollar derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US Dollar. The value of the conversion...
Create a ‘Student’ table using SQL query. The table must have at least five attributes from...
Create a ‘Student’ table using SQL query. The table must have at least five attributes from your choice with different data types.
When purchasing a car, one must take into account the attributes that impact each vehicle. These...
When purchasing a car, one must take into account the attributes that impact each vehicle. These attributes consist of car finance and insurance payments, seating, all-wheel drive, doors, motor size, mileage, gas economy, cost for keeping the vehicles for six years and cost of maintenance for an Acura RDX 2018. Please cite all sources.
You must label each answer with the number of question. Each question must have at least...
You must label each answer with the number of question. Each question must have at least three sentence answers. There is no maximum sentence, use as many as you wish to thoroughly answer the question. All answers must be complete sentences using proper grammar and spelling. Sarah paid $50,000 for a franchise that covers the entire United States. She intended to sell individual franchises for the each state. Naturally, investors considering buying a franchise from her asked to see the...
You must label each answer with the number of question. Each question must have at least...
You must label each answer with the number of question. Each question must have at least three sentence answers. There is no maximum sentence, use as many as you wish to thoroughly answer the question. All answers must be complete sentences using proper grammar and spelling. Assume you are opening a furniture store. You have some decisions about how to do the accounting for the business. Which type of inventory system will you use? Explain your reasons. specific, LIFO, FIFO,...
A firm needs to stand out on at least one attribute of the value proposition to...
A firm needs to stand out on at least one attribute of the value proposition to demonstrate a competitive advantage. true or false
Select three services: one high in search attributes, one high in experience attributes, and one high...
Select three services: one high in search attributes, one high in experience attributes, and one high in credence attributes. Describe what product characteristics make them easy or difficult for customers to evaluate and suggest specific strategies that marketers can adopt in each case to facilitate evaluation and reduce perceived risk.
Classes must have at least one field (T or F)
Classes must have at least one field (T or F)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT