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
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 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]
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...
Write code in SQL. Q1) By looking at city table. Write a query that identify the...
Write code in SQL. Q1) By looking at city table. Write a query that identify the in how many cities the company has branches. Rename the column name to TotalNumberOfCities. You have to look at city table and write a query to count number of rows. Q2) By looking at film table. How many films we have that its description contains the word "Robot". Count number of films and rename the column to NumberofRobots Q3) By looking at film table....
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...
USE C++ TO WRITE THIS CODE, MUST USE AN ARRAY An unknown number of grades as...
USE C++ TO WRITE THIS CODE, MUST USE AN ARRAY An unknown number of grades as integers, but no more than 30, are to be read from the file grades.dat. You may assume each grade will be a valid value between 0 and 100 (no validation necessary) and all "grades" are out of a maximum 100 points. Output the Number of Grades read in from the file. Calculate and output the Total Points Earned. Calculate and output the Total Possible...
(a) Write an algorithm (use pseudo-code) to determine whether a function f ∶ Z100 → Z100...
(a) Write an algorithm (use pseudo-code) to determine whether a function f ∶ Z100 → Z100 is surjective. That is, supply a “Method” to go with Input: A function (array) f with f(i) ∈ Z100 for i = 0, 1, . . . , 99. Output: Boolean B. B=‘true’ if f is surjective, ‘false’ otherwise. Try to make your algorithm as efficient as possible. Do NOT include an implementation of your algorithm in a programming language. (b) How many comparisons...
1. Please write the following in C++ also please show all output code and comment on...
1. Please write the following in C++ also please show all output code and comment on code. 2. Also, use CPPUnitLite to write all test and show outputs for each test. Write CppUnitLite tests to verify correct behavior for all the exercises. The modifications are aimed at making the exercises more conducive to unit tests. Write a function that swaps (exchanges the values of two integers). Use int* as the argument type. Write a second swap function using a reference...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT