Browse Source

<HW8>upd1 done

Mark 2 years ago
parent
commit
638678ed6e
2 changed files with 30 additions and 5 deletions
  1. 30 5
      08/main.js
  2. 0 0
      09/main.js

+ 30 - 5
08/main.js

@@ -36,12 +36,37 @@ var phone = {
    color: "black",
 };
 function filter(object, callback) {
-   let filterPhone = {};
+   let filterPhone = {}
    for (let key in object) {
-      if (callback(key, object[key])) {
-         filterPhone[key] = object[key];
-      }
+      if (callback(key, object[key]))
+         filterPhone = { ...filterPhone, [key]: object[key] };
    }
-   return filterPhone
+   return filterPhone;
 }
 console.log(filter(phone, (key, value) => key == "color" || value == 2));
+
+// object map
+function objectMap(object, callback) {
+   let filter = {}
+   for (let key in object) {
+      filter = { ...filter, ...callback([key], object[key]) };
+   }
+   return filter;
+}
+let finish = objectMap({ name: "Иван", age: 17 }, function (key, value) {
+   var result = {};
+   result[key + "_"] = value + "$";
+   return result;
+})
+console.log(finish)
+
+// Рекурсия
+// Sum
+let fact = n => n <= 0 ? 0 : n + fact(n - 1);
+console.log(fact(0))
+console.log(fact(1))
+console.log(fact(3))
+console.log(fact(5))
+console.log(fact(7))
+console.log(fact(9))
+

+ 0 - 0
09/main.js