-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootcamp_2020_36.js
More file actions
32 lines (32 loc) · 898 Bytes
/
bootcamp_2020_36.js
File metadata and controls
32 lines (32 loc) · 898 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
32
function count(array_search,search) {
var counter=0
for (let i = 0; i < array_search.length; i++){
if (array_search[i]==search){
counter++;
}
}
return counter
}
function dict_count(array) {
if (array.length ==0){
console.log({})
}
else{
var list_item=[];
var dict_tional={};
for (var i=0; i<array.length; i++){
if(list_item.includes(array[i])==false){
list_item.push(array[i]);
}
}
for (let k=0; k<list_item.length; k++) {
dict_tional[`${list_item[k]}`]=count(array,list_item[k]);
}
console.log(dict_tional);
}
}
dict_count([1,1,1,1,2,2,2,3,3,4,4,5]) ;
dict_count(["hey", "hi", "hi", "hi"]) ;
dict_count(["python", "python", "c++"]) ;
dict_count(["a", "b", "c", "d", "e"]) ;
dict_count([]) ;