justFiona

groupPeople

Jan 16th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.  
  3. function Person(firstName, lastName, age) {
  4.   this.firstName = firstName;
  5.   this.lastName = lastName;
  6.   this.age = age;
  7.   Person.prototype.fullData = function(){
  8.     return firstName + lastName + "\(age " + age +"\)";
  9.   };
  10. }
  11.  
  12. var people = [
  13.     new Person("Scott", "Guthrie", 38),
  14.     new Person("Scott", "Johns", 36),
  15.     new Person("Scott", "Hanselman", 39),
  16.     new Person("Jesse", "Liberty", 57),
  17.     new Person("Jon", "Skeet", 38)
  18. ];
  19.  
  20. var criteria = "age";
  21. var matchArr = {};
  22. for (var i = 0; i < people.length; i++){
  23.   var key = "Group " + people[i][criteria].toString();
  24.   matchArr[key] = people[i].firstName + " " + people[i].lastName + "(age " + people[i].age + ")";
  25. }
  26.  
  27. console.log(matchArr);
  28.  
  29. </script>
Advertisement
Add Comment
Please, Sign In to add comment