{"ScriptPreparationCode":null,"TestCases":[{"Name":"arr.filter","Code":"count = function(arr, item) {\r\n\treturn arr.filter(function(x){return x==item}).length\r\n}\r\n\r\ncount([1,2,3,2,4,2], 2);","IsDeferred":false},{"Name":"for","Code":"count = function(arr, item) {\r\n\tvar count = 0;\r\n\tfor(var i = 0; i \u003C arr.length; \u002B\u002Bi){\r\n \tif(arr[i] == item)\r\n \tcount\u002B\u002B;\r\n\t}\r\n \r\n\treturn count\r\n}\r\n\r\ncount([1,2,3,2,4,2], 2);","IsDeferred":false},{"Name":"arr.reduce","Code":"count = function(arr, item) {\r\n\treturn arr.reduce(function(total,x){return x==item ? total\u002B1 : total}, 0);\r\n}\r\n\r\ncount([1,2,3,2,4,2], 2);","IsDeferred":false},{"Name":"regex","Code":"count = function(arr, item) {\r\n\tvar regex = new RegExp(\u0027[^\u0027\u002Bitem\u002B\u0027]\u002B\u0027, \u0027g\u0027);\r\n\treturn String(arr).replace(regex,\u0027\u0027).length\r\n}\r\n\r\ncount([1,2,3,2,4,2], 3);","IsDeferred":false},{"Name":"indexOf","Code":"count = function(arr, item) {\r\n\tvar count= 0, i;\r\n\twhile((i= arr.indexOf(item, i))!= -1){\r\n\t\t\u002B\u002Bcount;\r\n\t\t\u002B\u002Bi;\r\n\t}\t\r\n\treturn count;\r\n}\r\n\r\ncount([1,2,3,2,4,2], 2);","IsDeferred":false}]}