{"ScriptPreparationCode":"function filter(iterable, predicate) {\r\n const iter = iterable[Symbol.iterator]();\r\n \r\n return {\r\n [Symbol.iterator]() {\r\n return this;\r\n },\r\n next() {\r\n let result;\r\n \r\n \twhile (\r\n !(result = iter.next()).done \u0026\u0026\r\n !predicate(result.value)\r\n );\r\n \r\n \treturn result;\r\n }\r\n };\r\n}\r\n\r\nfunction* filterGenerator(iterable, predicate){\r\n for (const value of iterable) {\r\n if (predicate(value)) {\r\n yield value;\r\n }\r\n }\r\n}\r\n\r\nvar arr = Array(100).fill(0).map((_, i) =\u003E i \u002B 1);\r\nvar predicate = (x) =\u003E x % 3 === 0 \u0026\u0026 x % 5 === 0;\r\n\r\nvar test1 = 0, test2 = 0, test3 = 0, test4 = 0, test5 = 0;","TestCases":[{"Name":"Loop with conditions","Code":"for (const value of arr) {\r\n\tif (predicate(value)) {\r\n\t\ttest1 \u002B= value;\r\n\t}\r\n}\r\n\r\nconsole.log(test1, \u0027test1\u0027);","IsDeferred":false},{"Name":"Iterator","Code":"for (const value of filter(arr, predicate)) {\r\n\ttest2 \u002B= value;\r\n}\r\n\r\nconsole.log(test2, \u0027test2\u0027);","IsDeferred":false},{"Name":"Generator","Code":"for (const value of filterGenerator(arr, predicate)) {\r\n\ttest3 \u002B= value;\r\n}\r\n\r\nconsole.log(test3, \u0027test3\u0027);","IsDeferred":false},{"Name":".forEach","Code":"arr.forEach((x) =\u003E {\r\n\tif (predicate(x)) test4 \u002B= x;\r\n});\r\nconsole.log(test4, \u0027test4\u0027);","IsDeferred":false},{"Name":"fori","Code":"for (let i = 0; i \u003C arr.length; i\u002B\u002B) {\r\n\tif (predicate(arr[i])) {\r\n\t\ttest5 \u002B= arr[i];\r\n }\r\n}\r\n\r\nconsole.log(test5, \u0027test5\u0027);","IsDeferred":false}]}