FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
hackerrankSolutions-JavaScript/Greedy/minAbsDiffInArray.js at master · aditiraj/hackerrankSolutions-JavaScript · GitHub
aditiraj
/
hackerrankSolutions-JavaScript
Public
Notifications
You must be signed in to change notification settings
Fork
46
Star
101
Code
Issues
1
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
hackerrankSolutions-JavaScript
/
Greedy
/
minAbsDiffInArray.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (18 loc) · 574 Bytes
Breadcrumbs
hackerrankSolutions-JavaScript
/
Greedy
/
minAbsDiffInArray.js
Copy path
File metadata and controls
21 lines (18 loc) · 574 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
function
minimumAbsoluteDifference
(
n
,
arr
)
{
// Sort the array as it will give the minimum difference between the consecutive elements.
arr
.
sort
(
function
(
a
,
b
)
{
return
a
-
b
}
)
;
let
val
,
diff
=
Number
.
MAX_VALUE
;
for
(
let
num
of
arr
)
{
if
(
val
!==
undefined
)
{
diff
=
Math
.
min
(
diff
,
Math
.
abs
(
val
-
num
)
)
;
}
val
=
num
;
}
console
.
log
(
diff
)
;
}
function
main
(
)
{
var
n
=
parseInt
(
readLine
(
)
)
;
arr
=
readLine
(
)
.
split
(
' '
)
;
arr
=
arr
.
map
(
Number
)
;
var
result
=
minimumAbsoluteDifference
(
n
,
arr
)
;
}
Back
|
FazBrowse Home
|
New Git URL