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
//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:
Get Answers For Free
Most questions answered within 1 hours.