FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/algorithms/binarySearchRecursive.js at master · lgope/JavaScript · GitHub
lgope
/
JavaScript
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
11
Code
Issues
0
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
algorithms
/
binarySearchRecursive.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
17 lines (11 loc) · 492 Bytes
Breadcrumbs
JavaScript
/
algorithms
/
binarySearchRecursive.js
Copy path
File metadata and controls
17 lines (11 loc) · 492 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
const
binarySearch
=
(
arr
,
val
,
start
=
0
,
end
=
arr
.
length
-
1
)
=>
{
const
mid
=
Math
.
floor
(
(
start
+
end
)
/
2
)
;
if
(
val
===
arr
[
mid
]
)
return
mid
;
if
(
start
>=
end
)
return
-
1
;
return
val
<
arr
[
mid
]
?
binarySearch
(
arr
,
val
,
start
,
mid
-
1
)
:
binarySearch
(
arr
,
val
,
mid
+
1
,
end
)
;
}
;
const
arr
=
[
1
,
9
,
5
,
7
,
2
,
4
,
8
,
6
]
.
sort
(
)
;
const
result
=
binarySearch
(
arr
,
2
)
;
console
.
log
(
result
!==
-
1
?
`Element is present at index
${
result
}
`
:
'Element is not present in array'
)
;
Back
|
FazBrowse Home
|
New Git URL