Advertisement
Guest User

[Exam Problems] JavaScript Basics Exam - 24 November 2014 -

a guest
Mar 29th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var arr = ["level^courses",
  2.     "{\"id\":0,\"firstname\":\"Angel\",\"lastname\":\"Ivanov\",\"town\":\"Plovdiv\",\"role\":\"student\",\"grades\":[\"5.89\"],\"level\":2,\"certificate\":false}",
  3.     "{\"id\":1,\"firstname\":\"Mitko\",\"lastname\":\"Nakova\",\"town\":\"Dimitrovgrad\",\"role\":\"trainer\",\"courses\":[\"PHP\",\"Unity Basics\"],\"lecturesPerDay\":6}",
  4.     "{\"id\":2,\"firstname\":\"Bobi\",\"lastname\":\"Georgiev\",\"town\":\"Varna\",\"role\":\"student\",\"grades\":[\"5.59\",\"3.50\",\"4.54\",\"5.05\",\"3.45\"],\"level\":4,\"certificate\":false}",
  5.     "{\"id\":3,\"firstname\":\"Ivan\",\"lastname\":\"Ivanova\",\"town\":\"Vidin\",\"role\":\"trainer\",\"courses\":[\"JS\",\"Java\",\"JS OOP\",\"Database\",\"OOP\",\"C#\"],\"lecturesPerDay\":7}",
  6.     "{\"id\":4,\"firstname\":\"Mitko\",\"lastname\":\"Petrova\",\"town\":\"Sofia\",\"role\":\"trainer\",\"courses\":[\"Database\",\"JS Apps\",\"Java\"],\"lecturesPerDay\":2}"
  7. ]
  8. mess(arr)
  9.  
  10. function mess (input) {
  11.  
  12.     var result = {students:[], trainers:[]}
  13.  
  14.     for (var i = 1; i < input.length; i++) {
  15.         var line = {}
  16.         line = JSON.parse(input[i])
  17. //        console.log(line)
  18.         if (line['role']=='student'){
  19.             result.students.push(line)
  20.         }
  21.         else if (line['role']=='trainer'){
  22.             result.trainers.push(line)
  23.         }
  24.     }
  25.     console.log(result)
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement