Question

Use visual studio code to write the javascript programme. Write a function that counts the number...

Use visual studio code to write the javascript programme.

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

Homework Answers

Answer #1

//JavaScript-C24.2.0 (SpiderMonkey)
//sample input
var colors = [ 'red', 'black', 'white', 'black', 'red' ]

//to get groupBY count
function groupByCount(colors) {
var result = {};
colors.map( function (a) { if (a in result) result[a] ++; else result[a] = 1; } );
return result;
}

//Calling method
objs = groupByCount(colors)

// To print values
for (var key in objs) {
print(key, objs[key])
}

Code sample:

Sample output:

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 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. Attributes such as ID, name etc do not count as categorical or numeric attributes. Exercise 1 (a) Define a class for your item that meets the above three categorical and one numeric attribute requirements. (b) Create a text file that contains at least 5 such records in CSV format. (c) Create a HTML page that contains a table element the shows one item record...
Use visual studio code to write the javascript programme. For this lab you must use a...
Use visual studio code to write the javascript programme. For this lab you must use a reasonable faceted search example, each item must have at least three categorical attributes and at least one numeric attribute. Attributes such as ID, name etc do not count as categorical or numeric attributes. (a) Define a class for your item that meets the above three categorical and one numeric attribute requirements. (b) Create a text file that contains at least 5 such records in...
Use visual studio code to write the javascript programme. For this lab you must use a...
Use visual studio code to write the javascript programme. For this lab you must use a reasonable faceted search example, each item must have at least three categorical attributes and at least one numeric attribute. Attributes such as ID, name etc do not count as categorical or numeric attributes. (a) Define a class for your item that meets the above three categorical and one numeric attribute requirements. (b) Create a text file that contains at least 5 such records in...
Use Jvascript to write this code by Visual Studio Code For this lab you must use...
Use Jvascript to write this code by Visual Studio Code For this lab you must use a reasonable faceted search example, each item must have at least three categorical attributes and at least one numeric attribute. Attributes such as ID, name etc do not count as categorical or numeric attributes. (a) Design a web page that includes three input fields one for each categorical attribute and a button whose label is ‘filter’. Also extend your CSV faceted search item file...
Use R Studio (show the code and output) Please write an R function named “outlier_detect” to...
Use R Studio (show the code and output) Please write an R function named “outlier_detect” to return or print out the outliers from a given data vector. outlier_detect = function(x){ #x: a column of numeric vector Body of code }
visual studio VB.Net write a vb.net program to create an array of 15 structures, each structure...
visual studio VB.Net write a vb.net program to create an array of 15 structures, each structure contains the following fields: user name, number of posts, then write a sub to read from the keyboard values into the structures fields and write a function to find and return the average of number of posts for all users and write a sub to print the user name that has zero number of posts.[ number of posts could be from 0 or more]
how to rename a row in r studio, for example view(mydata) a b c red 1...
how to rename a row in r studio, for example view(mydata) a b c red 1 4 yellow 2 4 white* 5 6 black 0 6 pink 6 3 purple 10 5 I want to rename the row 4, white* to white. I need to remove the "*" also I want to add a new column, with repetition values for ex. new column 1 2 3 1 2 3 please help, how can I write in R-program
Write a function called char_counter that counts the number of a certain character in a text...
Write a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. The function returns charnum, the number of characters found. If the file is not found or character is not a valid char, the function return -1. As an example, consider the following run. The file "simple.txt" contains a single line: "This...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will produce the following report (as shown). The first item in the report is a number with starting value 1. Second column is the word “ X ” (representing the times symbol). Third column is the table-number (itself). Following is an equal sign “ = “ (representing a result). Last column is the result of the operation for that line or row which is the...
Program C++ (use visual studio) Q1. What default copy constructor does the compiler insert in the...
Program C++ (use visual studio) Q1. What default copy constructor does the compiler insert in the following class? class Student { string name; string id; double grade; }; =========================== Q2 .What is the factor transfer method used when the f() function is called from? void f(int n[]); int main() { int m[3]= {1, 2, 3}; f(m); } ================================== Q3. Write a program that produces a bigger() with a prototype as shown below and outputs a large value by inputting two...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT