|
@@ -90,4 +90,61 @@ function filter(obj) {
|
|
|
|
|
|
console.log(filter(phone));
|
|
|
|
|
|
-//-----------------------------------------------------------object map--------------------------------------------------------------------
|
|
|
+//-----------------------------------------------------------object map--------------------------------------------------------------------
|
|
|
+
|
|
|
+let someObject = {
|
|
|
+ name: "Иван",
|
|
|
+ age: 17
|
|
|
+};
|
|
|
+
|
|
|
+function map(obj) {
|
|
|
+ let temp = {};
|
|
|
+ for (let i in obj) {
|
|
|
+ temp[i + '_'] = i + '$';
|
|
|
+ }
|
|
|
+ return temp;
|
|
|
+}
|
|
|
+
|
|
|
+console.log(map(someObject));
|
|
|
+
|
|
|
+//-----------------------------------------------------------recursion--------------------------------------------------------------------
|
|
|
+
|
|
|
+// a1 + function (a1, inc) {
|
|
|
+// return a1 + inc
|
|
|
+// }
|
|
|
+
|
|
|
+// function arithmeticProgression(num, increment, rows) {
|
|
|
+// for (let i = 0; i < rows; i++) {
|
|
|
+// return num + arithmeticProgression(num + increment)
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+function arithmeticProgression(num, increment, rows) {
|
|
|
+ if (rows <= 1) {
|
|
|
+ return num;
|
|
|
+ }
|
|
|
+ return num + arithmeticProgression(num + increment, increment, rows - 1)
|
|
|
+}
|
|
|
+
|
|
|
+console.log(arithmeticProgression(1, 4, 8));
|
|
|
+
|
|
|
+
|
|
|
+function construct(obj) {
|
|
|
+ let node = obj.tagName;
|
|
|
+ if ("attr" in obj) {
|
|
|
+ for (let attrName in obj.attrs) {
|
|
|
+ node.setAttribute(attrName, obj.attrs[attrsName])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if("subtags" in obj) {
|
|
|
+ for(let child in obj.subtags) {
|
|
|
+ construct(obj.subtags[child]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if("text" in obj) {
|
|
|
+ node.innerText = obj.text;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|