Guest User

Untitled

a guest
Jul 16th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var PersonProto = {
  2.     name: '',
  3.     surname: '',
  4.     birthday: '',
  5.     id: 0,
  6. };
  7.  
  8. var mkPerson = function (name, surname, birthday, id) {
  9.     var sibling,
  10.         res = Object.create(PersonProto);
  11.     res.name = name;
  12.     res.surname = surname;
  13.     res.birthday = birthday;
  14.     res.children = [];
  15.     res.sibling = [];
  16.     res.mother = null;
  17.     res.father = null;
  18.     res.id = id;
  19.     return {
  20.         setMother: function (mother) {
  21.          res.mother = mother;
  22.          res.sibling = mother.getChildren();
  23.          mother.getChildren().push(res);
  24.         },
  25.         setFather: function (father) {
  26.           res.father = father;
  27.           father.getChildren().push(res);
  28.         },
  29.         getSibling: function () {
  30.           if (res.mother !== null) {
  31.              sibling = res.mother.getChildren();
  32.              sibling.splice(sibling.indexOf(res), 1);
  33.              return sibling;
  34.           }
  35.           else if (res.father !== null) {
  36.              sibling = res.father.getChildren();
  37.              sibling.splice(sibling.indexOf(res), 1);
  38.              return sibling;
  39.           }
  40.           else {
  41.              return [];
  42.           }
  43.         },
  44.         getChildren: function () {
  45.           return res.children;
  46.         }
  47.     }
  48. };
  49.  
  50. var syn = mkPerson('Syn', 'fsasfafas', '1996-10-10', 15);
  51. var mama = mkPerson('Mama', 'aaaa', '1966-10-10', 16);
  52. var tata = mkPerson('Tata', 'bbbb', '1966-10-10', 16);
  53. var corka = mkPerson('Corka', 'cccc', '1966-10-10', 16);
  54. var dziadek = mkPerson('Dziadek', 'bbasfasfbb', '1966-10-10', 16);
  55. var babcia = mkPerson('Babcia', 'bfasasfb', '1966-10-10', 16);
  56. var syn2 = mkPerson('Syn2', 'fsasfafas', '1996-10-10', 15);
  57.  
  58. syn.setMother(mama);
  59. syn.setFather(tata);
  60. syn2.setMother(mama);
  61. syn2.setFather(tata);
  62. corka.setMother(mama);
  63. corka.setFather(tata);
  64. mama.setMother(babcia);
  65. mama.setFather(dziadek);
  66.  
  67.  
  68. console.log(corka.getSibling());
Add Comment
Please, Sign In to add comment