Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var PersonProto = {
- name: '',
- surname: '',
- birthday: '',
- id: 0,
- };
- var mkPerson = function (name, surname, birthday, id) {
- var sibling,
- res = Object.create(PersonProto);
- res.name = name;
- res.surname = surname;
- res.birthday = birthday;
- res.children = [];
- res.sibling = [];
- res.mother = null;
- res.father = null;
- res.id = id;
- return {
- setMother: function (mother) {
- res.mother = mother;
- res.sibling = mother.getChildren();
- mother.getChildren().push(res);
- },
- setFather: function (father) {
- res.father = father;
- father.getChildren().push(res);
- },
- getSibling: function () {
- if (res.mother !== null) {
- sibling = res.mother.getChildren();
- sibling.splice(sibling.indexOf(res), 1);
- return sibling;
- }
- else if (res.father !== null) {
- sibling = res.father.getChildren();
- sibling.splice(sibling.indexOf(res), 1);
- return sibling;
- }
- else {
- return [];
- }
- },
- getChildren: function () {
- return res.children;
- }
- }
- };
- var syn = mkPerson('Syn', 'fsasfafas', '1996-10-10', 15);
- var mama = mkPerson('Mama', 'aaaa', '1966-10-10', 16);
- var tata = mkPerson('Tata', 'bbbb', '1966-10-10', 16);
- var corka = mkPerson('Corka', 'cccc', '1966-10-10', 16);
- var dziadek = mkPerson('Dziadek', 'bbasfasfbb', '1966-10-10', 16);
- var babcia = mkPerson('Babcia', 'bfasasfb', '1966-10-10', 16);
- var syn2 = mkPerson('Syn2', 'fsasfafas', '1996-10-10', 15);
- syn.setMother(mama);
- syn.setFather(tata);
- syn2.setMother(mama);
- syn2.setFather(tata);
- corka.setMother(mama);
- corka.setFather(tata);
- mama.setMother(babcia);
- mama.setFather(dziadek);
- console.log(corka.getSibling());
Add Comment
Please, Sign In to add comment