Jelajahi Sumber

HW8 changed done

Vadym Hlushko 3 tahun lalu
induk
melakukan
5d59ab0523
1 mengubah file dengan 7 tambahan dan 8 penghapusan
  1. 7 8
      hw8/main.js

+ 7 - 8
hw8/main.js

@@ -92,16 +92,15 @@ return previousValue
     color: "black",
 };
 
-function filter (object , name ,value) {
-  let result = {}
-  for (key in object) {
-    if (name == key || object[key] == value){
-      result[key] = object [key]
+function filter(object, someF) {
+    for(let key in object){
+        if(!someF(key, object[key])) {
+            delete object[key]
+        }
     }
-  }
-  return result
 }
-console.log (filter(phone,'color',2))
+filter(phone,(key,value) => key == "color" || value == 2);
+console.log(phone)
 
 //object map
 let obj = map({name: "Иван", age: 17},function(key,value){