فهرست منبع

<HW8>upd1 done

Mark 2 سال پیش
والد
کامیت
638678ed6e
2فایلهای تغییر یافته به همراه30 افزوده شده و 5 حذف شده
  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