Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ["Teacher 1", "Student 1", "Student 2", "Student 3", "Student 4", "Student 5"]
- ["Teacher 2", "Student 1", "Student 2", "Student 3", "Student 4", "Student 5"]
- Var Teacher1 = new Teacher("Teacher1");
- Teacher1.students = [Student1, Student2, Student3, Student4, Student5];
- // map takes an array and returns and modifies each object, passed
- // as the parameter d
- rows.map(function(d){
- return {
- teacher: d[0],
- students: d.slice(1)
- };
- });
- [
- {teacher: 'Teacher 1', students: ['Student 1', 'Student 2',...']},
- ]
- function Teacher(name){
- this.name = name;
- }
- var teacher = new Teacher('teacher 1')
- var teacher = {}; //an empty object
- teacher.name = 'teacher 1';
- teacher.students = ['student 1', ...]
- var teacher = {
- name: 'teacher 1',
- students: ['student 1',' student 2',...']
- };
- function example(item) {
- // where item is an array
- return {
- name: item[0],
- students: item.slice(1) // takes all the array elements after 0
- };
- }
- function Teacher(name, students) {
- this.name = name;
- this.students = students;
- }
- rows.map(function(d){
- return new Teacher(d[0], d.slice(1));
- });
- var myProcessedCSV = [
- ["Teacher 1", "Student 1", "Student 2", "Student 3", "Student 4", "Student 5"]
- ["Teacher 2", "Student 1", "Student 2", "Student 3", "Student 4", "Student 5"]
- ]
- // start the processing
- myProcessedCSV.forEach(processCSVRow);
- // this function takes a single row and instantiates a Teacher object
- // with it
- function processCSVRow(row){
- // this extracts the teacher's name (the first data in the row)
- var teacherName = row.shift();
- var teacher = new Teacher(teacherName);
- // all the remaining data points in the row are students, so we
- // can simply use 'row' here
- teacher.students = row;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement