|
@@ -0,0 +1,233 @@
|
|
|
+"use strict";
|
|
|
+
|
|
|
+
|
|
|
+//TODO: 3 persons
|
|
|
+let a = {
|
|
|
+ name: "Ivan",
|
|
|
+ surname: "Petrov",
|
|
|
+}
|
|
|
+
|
|
|
+let b = {
|
|
|
+ name: "Kate",
|
|
|
+ surname: "Smirnova",
|
|
|
+}
|
|
|
+
|
|
|
+let c = {
|
|
|
+ name: "Lisa",
|
|
|
+ surname: "Volkova",
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//TODO: different fields
|
|
|
+a.age = 16;
|
|
|
+a.sex = "male";
|
|
|
+b.fathername = "Aleksandrovna";
|
|
|
+c.age = 24;
|
|
|
+c.sex = "female";
|
|
|
+
|
|
|
+
|
|
|
+function fieldsCheck() {
|
|
|
+ for (let key in a) {
|
|
|
+ if (key == "name" || key == "surname") {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ console.log(a[key]);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let key in b) {
|
|
|
+ if (key == "name" || key == "surname") {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ console.log(b[key]);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let key in c) {
|
|
|
+ if (key == "name" || key == "surname") {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ console.log(c[key]);
|
|
|
+ }
|
|
|
+}
|
|
|
+// fieldsCheck()
|
|
|
+
|
|
|
+
|
|
|
+let persons = [a, b, c, {
|
|
|
+ name: "Sara",
|
|
|
+ surname: "Romanova",
|
|
|
+ fathername: "Tihomirovna"
|
|
|
+}];
|
|
|
+
|
|
|
+
|
|
|
+function loopOfPersons() {
|
|
|
+ for (let i = 0; i < persons.length; i++) {
|
|
|
+ console.log(persons[i])
|
|
|
+ };
|
|
|
+}
|
|
|
+// loopOfPersons()
|
|
|
+
|
|
|
+
|
|
|
+function loopOfNameSurname() {
|
|
|
+ for (let key of persons) {
|
|
|
+ console.log(`Name: ${key.name}, Surname: ${key.surname}`)
|
|
|
+ }
|
|
|
+}
|
|
|
+// loopOfNameSurname()
|
|
|
+
|
|
|
+
|
|
|
+function loopOfValues() {
|
|
|
+ for (let i in persons) {
|
|
|
+ for (let key in persons[i]) {
|
|
|
+ console.log(persons[i][key])
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+// loopOfValues()
|
|
|
+
|
|
|
+
|
|
|
+function fullName() {
|
|
|
+ for (let obj of persons) {
|
|
|
+ obj.fullName = `${obj.surname} ${obj.name}`;
|
|
|
+ if (obj.fathername) {
|
|
|
+ obj.fullName += ` ${obj.fathername}`;
|
|
|
+ }
|
|
|
+ console.log(obj);
|
|
|
+ }
|
|
|
+}
|
|
|
+// fullName()
|
|
|
+
|
|
|
+
|
|
|
+function serialize() {
|
|
|
+ let objJson = JSON.stringify(persons);
|
|
|
+}
|
|
|
+// serialize()
|
|
|
+
|
|
|
+
|
|
|
+function deserialize() {
|
|
|
+ let obj = JSON.parse(`{"name":"Lara","surname":"Koval","age":12,"sex":"female"}`);
|
|
|
+ persons.push(obj);
|
|
|
+ console.log(persons);
|
|
|
+}
|
|
|
+// deserialize()
|
|
|
+
|
|
|
+
|
|
|
+function html() {
|
|
|
+ let str = "<table border='1'>"
|
|
|
+ for (let i = 0; i < persons.length; i++) {
|
|
|
+ str +=
|
|
|
+ `<tr>
|
|
|
+ <td>${persons[i]["name"]}</td>
|
|
|
+ <td>${persons[i]["surname"]}</td>
|
|
|
+ </tr>`
|
|
|
+ console.log(persons[i])
|
|
|
+ }
|
|
|
+ str += "</table>"
|
|
|
+
|
|
|
+ console.log(str);
|
|
|
+ document.write(str);
|
|
|
+}
|
|
|
+// html()
|
|
|
+
|
|
|
+
|
|
|
+function htmlOptionalFields() {
|
|
|
+ let str = "<table border='1'>"
|
|
|
+ for (let i = 0; i < persons.length; i++) {
|
|
|
+ if ((i % 2) == 0) {
|
|
|
+ str += "<tr bgcolor='grey'>"
|
|
|
+ }
|
|
|
+ for (let key in persons[i]) {
|
|
|
+ str += `<td>${persons[i][key]}</td>`
|
|
|
+ }
|
|
|
+ str += "</tr>"
|
|
|
+ console.log(persons[i]);
|
|
|
+ }
|
|
|
+ str += "</table>"
|
|
|
+
|
|
|
+ console.log(str);
|
|
|
+ document.write(str);
|
|
|
+}
|
|
|
+// htmlOptionalFields()
|
|
|
+
|
|
|
+
|
|
|
+function blueBelt() {
|
|
|
+ let someTree = {
|
|
|
+ tagName: "table",
|
|
|
+ subTags: [{
|
|
|
+ tagName: "tr",
|
|
|
+ subTags: [{
|
|
|
+ tagName: "td",
|
|
|
+ text: "some text",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: "td",
|
|
|
+ text: "some text",
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }],
|
|
|
+ attrs: {
|
|
|
+ border: 1,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ let str = "<table border=1>"
|
|
|
+ for (let i = 0; i < 1; i++) {
|
|
|
+ str +=
|
|
|
+ `<tr>
|
|
|
+ <td>${"some text"}</td>
|
|
|
+ <td>${"some text"}</td>
|
|
|
+ </tr>`
|
|
|
+ }
|
|
|
+ str += "</table>"
|
|
|
+ document.write(str)
|
|
|
+}
|
|
|
+// blueBelt()
|
|
|
+
|
|
|
+
|
|
|
+function destructArray() {
|
|
|
+ let arr = [1, 2, 3, 4, 5, "a", "b", "c"];
|
|
|
+ let [odd1, even1, odd2, even2, odd3, ...rest] = arr;
|
|
|
+ console.log(rest);
|
|
|
+}
|
|
|
+// destructArray()
|
|
|
+
|
|
|
+
|
|
|
+function destructString() {
|
|
|
+ let arr = [1, "abc"];
|
|
|
+ let [number, [s1, s2, s3]] = arr;
|
|
|
+
|
|
|
+ console.log(number);
|
|
|
+ console.log(s1);
|
|
|
+ console.log(s2);
|
|
|
+ console.log(s3);
|
|
|
+}
|
|
|
+// destructString()
|
|
|
+
|
|
|
+
|
|
|
+function destruct2() {
|
|
|
+ let obj = {
|
|
|
+ name: 'Ivan',
|
|
|
+ surname: 'Petrov',
|
|
|
+ children: [{
|
|
|
+ name: 'Maria'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'Nikolay'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ let [name1, name2] = [obj.children[0].name, obj.children[1].name];
|
|
|
+ console.log(name1);
|
|
|
+ console.log(name2);
|
|
|
+}
|
|
|
+// destruct2()
|
|
|
+
|
|
|
+
|
|
|
+function destruct3() {
|
|
|
+ let arr = [1, 2, 3, 4, 5, 6, 7, 10];
|
|
|
+ let [[a, b], length] = [arr, arr.length];
|
|
|
+
|
|
|
+ console.log(a);
|
|
|
+ console.log(b);
|
|
|
+ console.log(length);
|
|
|
+}
|
|
|
+// destruct3()
|