FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm-practice/javascript/4_array-programs/uniqueValue.js at main · amit265/algorithm-practice · GitHub
amit265
/
algorithm-practice
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm-practice
/
javascript
/
4_array-programs
/
uniqueValue.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
40 lines (29 loc) · 790 Bytes
Breadcrumbs
algorithm-practice
/
javascript
/
4_array-programs
/
uniqueValue.js
Copy path
File metadata and controls
executable file
·
40 lines (29 loc) · 790 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
33
34
35
36
37
38
39
40
// 11. Remove Duplicate Elements from an Array (Unique Values)
function
removeDuplicates
(
)
{
let
a
=
[
10
,
20
,
20
,
30
,
40
,
50
,
50
]
;
let
s
=
new
Set
(
a
)
;
let
a1
=
[
...
s
]
;
return
a1
;
}
console
.
log
(
removeDuplicates
(
)
)
;
//Using JavaScript forEach() with array.includes() method
let
b
=
[
10
,
20
,
30
,
30
,
40
,
40
]
;
let
c
=
[
]
;
b
.
forEach
(
(
elm
)
=>
{
if
(
!
c
.
includes
(
elm
)
)
{
c
.
push
(
elm
)
;
}
}
)
;
console
.
log
(
c
)
;
// Using JavaScript filter() Method with indexOf method
const
d
=
[
10
,
20
,
30
,
30
,
40
,
40
,
50
,
60
]
;
const
e
=
d
.
filter
(
(
item
,
index
)
=>
d
.
indexOf
(
item
)
===
index
)
;
console
.
log
(
e
)
;
// Using JavaScript reduce() with array.includes() method
const
f
=
d
.
reduce
(
(
acc
,
curr
)
=>
{
if
(
!
acc
.
includes
(
curr
)
)
{
acc
.
push
(
curr
)
;
}
return
acc
;
}
,
[
]
)
;
console
.
log
(
f
)
;
Back
|
FazBrowse Home
|
New Git URL