Question

In: Computer Science

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 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. For the next question choose one of your categorical attributes.


use javascript


Solutions

Expert Solution

class Item {

constructor(name, color) {

this.name = name;

this.color = color;

}

print(){

console.log("Name: ",this.name, "\nColor: ",this.color);

}

}


function loadcsv(filename,delimiter=","){

var fs = require('fs');

var array = fs.readFileSync(filename).toString().split("\n");

var items = new Array();

array.forEach(element => {

obj = element.split(delimiter);

items.push(new Item(obj[0],obj[1]));

});

return items;

}

items = loadcsv("./list.csv")

console.log(items);

Here is the snapshot of run.


Related Solutions

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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT