Selaa lähdekoodia

HW<SB79RZ2XNFB> done

Andrey 3 vuotta sitten
commit
97e966624e
3 muutettua tiedostoa jossa 128 lisäystä ja 0 poistoa
  1. 15 0
      project/.vscode/launch.json
  2. 13 0
      project/index.html
  3. 100 0
      project/js/main.js

+ 15 - 0
project/.vscode/launch.json

@@ -0,0 +1,15 @@
+{
+    // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
+    // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
+    // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "pwa-chrome",
+            "request": "launch",
+            "name": "Launch Chrome against localhost",
+            "url": "http://localhost:8080",
+            "webRoot": "${workspaceFolder}"
+        }
+    ]
+}

+ 13 - 0
project/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+	<meta charset="utf-8">
+	<title>Homework</title>
+	<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+	<link rel="stylesheet" href="css/style.css">
+	<link rel="stylesheet" href="css/normalize.css">
+</head>
+<body>
+	<script src="js/main.js"></script>
+</body>
+</html>

+ 100 - 0
project/js/main.js

@@ -0,0 +1,100 @@
+//sort
+
+// var persons = [
+//     { name: "Иван", age: 17 },
+//     { name: "Мария", age: 35 },
+//     { name: "Алексей", age: 73 },
+//     { name: "Яков", age: 12 }
+//   ];
+//   function sort(persons, name, boolean) {
+//     if (boolean === true || boolean == null) {
+//       for (let i = 0; i < persons.length; i++) {
+//         for (let k = 0; k < persons.length - 1; k++) {
+//           if (persons[k][name] > persons[k + 1][name]) {
+//             let c = persons[k];
+//             persons[k] = persons[k + 1];
+//             persons[k + 1] = c;
+//           }
+//         }
+//       }
+//     } else {
+//       for (let i = 0; i < persons.length; i++) {
+//         for (let k = 0; k < persons.length - 1; k++) {
+//           if (persons[k][name] < persons[k + 1][name]) {
+//             let c = persons[k];
+//             persons[k] = persons[k + 1];
+//             persons[k + 1] = c;
+//           }
+//         }
+//       }
+//     }
+//   }
+//   sort(persons, "age");
+//   console.log(persons);
+//   sort(persons, "name",false);
+//   console.log(persons);
+
+
+//array Map
+
+// arr = ["1", {}, null, undefined, "500", 700];
+// let result = arr.map(function(item,index,arr){
+//     var numbers = parseInt(item);
+//     return isNaN(numbers) ? item : numbers;
+// })
+
+//array reduce
+// arr = ["0", 5, 3, "string", null]
+// let result = arr.reduce(function(accumulator, currentValue){
+//     if (typeof(currentValue) == 'number'){
+//         accumulator *= currentValue
+//     }
+//     return accumulators;
+// },1)
+// alert(result)
+
+//object filter
+// var phone = {
+//     brand: "meizu",
+//     model: "m2",
+//     ram: 2,
+//     color: "black",
+// };
+
+// function filter(arr,f){
+//   let result = []
+//  for (let item in arr){
+//      if(f(item,arr[item])){
+//       result[item] = arr[item]
+//      }
+//  }
+//  console.log(result)
+//  }
+//  filter(phone,(key,value) => key == "color" || value == 2);
+
+// object map
+
+//  function map(obj,callback){
+//     for(let key in obj){
+//       var obj1 = callback(key,obj[key]);
+//       delete obj[key]
+//       for (key in obj1)
+//       obj[key] = obj1[key]
+//       return obj
+//     }
+// }
+// let obj = map({name: "Иван", age: 17},function(key,value){
+//   var result = {};
+//   result[key+"_"] = value + "$";
+//   return result;
+// })
+// console.log(obj)
+
+
+// Sum
+function sumRec(a){
+    if (a > 1){
+    return a + sumRec(a-1)}
+    return 1;
+  }
+  console.log(sumRec(3))