|
@@ -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))
|
|
|
+
|