Emmanuil преди 4 години
родител
ревизия
23734cc1b5
променени са 1 файла, в които са добавени 59 реда и са изтрити 3 реда
  1. 59 3
      js-07/js.js

+ 59 - 3
js-07/js.js

@@ -16,11 +16,67 @@
 
 // console.log(persons.sort());
 
-
 // array map
 // var arrMay = ["1", {}, null, undefined, "500", 700]
+
 // var result = arrMay.map(function(item){
 //     var number = parseInt(item);
-//     return isNaN(number) ? item : number;
+//     return isNaN(number) ? item : number
+// })
+// console.log(result)
+
+// array reduce
+// var arr = ["0", 5, 3, "string", null];
+
+// var result = arr.reduce(function(item, mul){
+//     return typeof(mul) === 'number' ? item *= mul : item
+// }, 1)
+// console.log(result);
+
+// object filter
+// var phone = {
+//   brand: "meizu",
+//   model: "m2",
+//   ram: 2,
+//   color: "black",
+// };
+
+// function filter(obj, key, value) {
+//   var itog = {};
+//   for (let item in obj) {
+//       if (key === item || obj[item] === value) itog[item] = obj[item];
+//   }
+//   return itog;
+// }
+// console.log(filter(phone, "color", 2))
+
+
+
+// object map
+// map({ name: "Иван", age: 17 }, function (key, value) {
+//   var result = {};
+//   result[key + "_"] = value + "$";
+//   return result;
+// }); 
+//должен вернуть {name_: "Иван$", age_: "17$"}
+
+
+
+// var person = [
+//   {name: "Иван"},
+//   {age: 17}
+// ]
+
+// var newPerson = person.map(function(obj){
+//   var result = {}
+
+//   for (var key in obj){
+//     var personName = key + "_"
+//     var personAge = obj[key] + "$"
+//   }
+
+//   result[personName] = personAge
+//   return result
 // })
-// console.log(result)
+
+// console.log(newPerson)