- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbltrbl.js
More file actions
Latest commit
19 lines (17 loc) · 483 Bytes
/
Copy pathDbltrbl.js
File metadata and controls
19 lines (17 loc) · 483 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
functiondbltrbl(ary){
letseen=newSet()
for(letindex=0;index<ary.length;index++){
constelement=ary[index];
// Double the element if it hasn't been seen before
if(!seen.has(element)){
ary[index]=element*2;
seen.add(element);// Mark this element as doubled
}
}
returnary;
}
constmain=()=>{
letaary=[1,2,2,2,3,4,5,6,7,8,9];
console.log(dbltrbl(aary));
}
main()