-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
31 lines (25 loc) · 748 Bytes
/
test.js
File metadata and controls
31 lines (25 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
movie = ["spy","ray","spy","room","once","ray","spy","once"];
solution(movie);
function solution(movie) {
var movieName = [];
var movieCounts = [];
var movieAnswer = [];
for (var i in movie)
{
var idx = movie[i];
movieName[idx] = movie[i];
if(typeof(movieCounts[idx])=='undefined')
movieCounts[idx]=1;
else
movieCounts[idx]++;
}
movieName = movieName.filter(function(){ return true});
movieCounts = movieCounts.filter(function(){ return true});
var movieObj=[];
for(var i=0; i<movieName.length; i++)
{
movieObj.push({title:movieName[i],count:movieCounts[movieName]});
}
console.log(movieObj);
return movieObj;
}