Vika 3 years ago
parent
commit
3f9f3d3e70
3 changed files with 210 additions and 0 deletions
  1. 13 0
      js7/index.html
  2. 197 0
      js7/main.js
  3. 0 0
      js7/style.css

+ 13 - 0
js7/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+  <link href="style.css" rel="stylesheet">
+</head>
+<body>
+  <script src="main.js"></script> 
+</body>
+</html>

+ 197 - 0
js7/main.js

@@ -0,0 +1,197 @@
+// Task sort
+// let persons = [
+//   {name: "Иван", age: 17},
+//   {name: "Мария", age: 35},
+//   {name: "Алексей", age: 73},
+//   {name: "Яков", age: 12},
+// ];
+
+// function sort (arr, key, boolean = true) {
+//   for (let i = 0; i < (arr.length - 1); i++) {
+//     for (let q = 0; q < arr.length - 1; q++) {
+//       if (arr[q][key] > arr[q + 1][key]) {
+//         let b = arr[q];
+//         arr[q] = arr[q + 1];
+//         arr[q + 1] = b;
+//       }; 
+//       if ((arr[q][key] < arr[q + 1][key]) && !boolean ) {
+//         let b = arr[q];
+//         arr[q] = arr[q + 1];
+//         arr[q +1] = b;
+//       }; 
+//     };
+//   };console.log(arr);
+//   return arr;
+// };
+
+// sort(persons, 'name', false);
+
+
+//Task array map
+
+// let myArray = ["1", {}, null, undefined, "500", 700];
+
+// function changStringToNumber (arr) {
+//   for (let i = 0; i < arr.length; i++) {
+//     if (typeof (arr[i]) === 'string') {
+//       arr[i] = +arr[i];
+//     };
+//   };
+//   console.log(arr);
+//   return arr;
+// };
+
+// changStringToNumber(myArray);
+//2
+// let myArray = ["1", {}, null, undefined, "500", 700];
+// let newArray = myArray.map( function (value) {
+//   if (typeof(value) === 'string') {
+//     value = +value;
+//     return value;
+//   };
+//   return value;
+// });  
+// console.log(newArray);
+
+
+
+
+//Task array reduce
+
+// let myArray = ["0", 5, 3, "string", null];
+
+// function multiplicationStrings (arr) {
+//   let result = 1;
+//   for (let i = 0; i < arr.length; i++) {
+//     if (typeof (arr[i]) === 'number') {
+//       result *= (+arr[i]);
+//     };
+//   };
+//   console.log(result);
+//   return result;
+// }; 
+
+// multiplicationStrings(myArray);
+//2
+
+// let myArray = ["0", 5, 3, "string", null];
+// let result = myArray. reduce(function multiplicationStrings (acum, curentVal) {
+//   if (typeof(curentVal) === 'number') {
+//     return (acum * curentVal);
+//   };
+//   return acum;
+//  }, 1);
+//  console.log(result);
+
+
+//Task object filter
+
+// var phone = {
+//   brand: "meizu",
+//   model: "m2",
+//   ram: 2,
+//   color: "black",
+// };
+
+// function myFilter (obj, func) {
+//   let newObj = {};
+//   for (let key in obj) {
+//     let checkArg = func (key, value =obj[key]);
+//     if (checkArg) {
+//       newObj[key] = value;
+//     }; 
+//   };
+//   return newObj;
+// };
+
+
+// let check = myFilter(phone,(key,value) => key == "color" || value == 2);
+// console.log (check);
+
+
+//Task object map
+
+// function myMap (obj, func) {
+//   let newObj = {};
+//   for (let key in obj) {
+//     let checkArg = func (key, value =obj[key]);
+//     Object.assign(newObj,checkArg);
+//   };
+//   return newObj;
+// };
+// let check = myMap({name: "Иван", age: 17},function(key,value){
+//   var result = {};
+//   result[key+"_"] = value + "$";
+//   return result;
+// }); //должен вернуть {name_: "Иван$", age_: "17$"}
+
+// console.log(check);
+
+
+
+// Task Sum
+
+// function calculationSumArithmProgr (a, d, n) {
+ 
+//   if (n === 1) {
+//     return a;
+//   };
+
+//   return (calculationSumArithmProgr(a, d, n-1) + (a + d * (n - 1)));
+// };
+
+// let check = calculationSumArithmProgr(5, 7, 3);
+// console.log(check);
+
+
+//Task HTML Tree
+var someTree = {
+  tagName: "table", //html tag
+  children: [ //вложенные тэги
+      {
+                  tagName: "tr",
+                  children: [
+                      {
+                          tagName: "td",
+                          text: "some text",
+                      },
+                      {
+                          tagName: "td",
+                          text: "some text 2",
+                      }
+                  ]
+      }
+  ],
+  attrs: 
+  {
+      border: 1,
+  },
+}
+
+function builder (obj) {
+  let {tagName, attrs, text, children} = obj;
+ 
+  let attributes = '';
+
+  if (attrs) {
+    for (const [key, value] of Object.entries(attrs)) {
+    attributes += `${key} = ${value}` ;
+    };
+  };
+
+  if (!children) {
+    return `<${tagName} ${attributes}>${text}</${tagName}>`;
+  };
+
+  let siblings = '';
+
+  for (let i = 0; i < children.length; i++) {
+    siblings += `${builder(children[i])}\n`;
+  };
+
+  return `<${tagName} ${attributes}>\n ${siblings}</${tagName}>\n`;
+};
+
+let check = builder(someTree);
+
+document.write(check);

+ 0 - 0
js7/style.css