makstravm vor 3 Jahren
Ursprung
Commit
b77a3d8a4c
3 geänderte Dateien mit 50 neuen und 15 gelöschten Zeilen
  1. 15 15
      HW6/main.js
  2. 17 0
      HW7/index.html
  3. 18 0
      HW7/main.js

+ 15 - 15
HW6/main.js

@@ -28,21 +28,21 @@ function sum() {
 }
 
 
-// var sample = prompt("Введите название задания")
-// switch (sample.toLowerCase()) {
-//   case "a": a('Привет')
-//     break
-//   case "cube": cube(5)
-//     break
-//   case "avg2": avg2(10, 8)
-//     break
-//   case "intRandom": intRandom(5, 25)
-//     break
-//   case "greetAll": greetAll("Superman", "SpiderMan", "Captain Obvious")
-//     break
-//   case "sum": sum(10, 20, 40, 100)
-//     break
-// }
+var sample = prompt("Введите название задания")
+switch (sample.toLowerCase()) {
+  case "a": a('Привет')
+    break
+  case "cube": cube(5)
+    break
+  case "avg2": avg2(10, 8)
+    break
+  case "intRandom": intRandom(5, 25)
+    break
+  case "greetAll": greetAll("Superman", "SpiderMan", "Captain Obvious")
+    break
+  case "sum": sum(10, 20, 40, 100)
+    break
+}
 
 const objFunction = {
   a: a,

+ 17 - 0
HW7/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en-ru">
+
+<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>HW7</title>
+
+</head>
+
+<body>
+  
+  <script src="main.js"></script>
+</body>
+
+</html>

+ 18 - 0
HW7/main.js

@@ -0,0 +1,18 @@
+var persons = [
+  { name: "Иван", age: 17 },
+  { name: "Мария", age: 35 },
+  { name: "Алексей", age: 73 },
+  { name: "Яков", age: 12 },
+]
+
+const sort = (obj, param, ascending = true) => obj.sort((a, b) => ascending ? (a[param] > b[param] ? 1 : -1) : (a[param] < b[param] ? 1 : -1))
+
+// console.log(sort(persons, "name", false)); //сортирует по имени по убыванию
+// console.log(sort(persons, "age", true)); //сортирует по возрасту по возрастанию
+
+
+let arrayMap = ["1", {}, null, undefined, "500", 700]
+let newArray = arrayMap.map(t => t === String(t) ? +t : t)
+
+let arrayrReduce = ["0", 5, 3, "string", null]
+let newarrayrReduce = arrayrReduce.reduce((a = 0, b) => typeof b === 'number' ? a * b : a, 1)