Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
00cc6a23
Commit
00cc6a23
authored
Feb 20, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify/rename findLowerClosestBound => findClosestIndex
parent
1e8559af
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
util.js
src/helpers/util.js
+13
-6
No files found.
src/helpers/util.js
View file @
00cc6a23
...
...
@@ -88,15 +88,22 @@ module.exports = {
/*
Binary Search:
Assumes that @arg array is sorted increasingly
return (saying middle=(array[i] + array[i + 1]) / 2 <= target) return i if target < middle; return i + 1 if target >= middle; return array.length - 1 if index > array.length; return null if array[0] > target || array is empty
return Return i such that |array[i] - target| is smallest among all i and -1 for an empty array.
Returns the smallest i for multiple candidates.
*/
findLowerClosestBound
:
function
(
target
,
array
)
{
var
index
=
this
.
findLowerBound
(
target
,
array
)
if
(
index
>
array
.
length
)
{
return
index
findClosestIndex
:
function
(
target
,
array
)
{
if
(
array
.
length
===
0
)
{
return
-
1
}
var
index
=
this
.
findLowerBound
(
target
,
array
)
if
(
index
<
0
)
{
return
array
[
0
]
}
else
if
(
index
>=
array
.
length
-
1
)
{
return
array
[
array
.
length
-
1
]
}
else
{
var
middle
=
(
array
[
index
]
+
array
[
index
+
1
])
/
2
return
target
>=
middle
?
index
+
1
:
index
return
target
<=
middle
?
index
:
index
+
1
}
},
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment