Skip to content

Commit f231e9a

Browse files
authored
feat: Convert to TypeScript (#5)
1 parent 1835653 commit f231e9a

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

src/index.js renamed to src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2323
*/
2424

25-
function compare(v1, v2) {
25+
export type CompareFunction = (v1: number, v2: number) => Boolean;
26+
27+
function compare(v1: number, v2: number) {
2628
return v1 < v2;
2729
}
2830

29-
function upperBound(array, value, comp = compare) {
31+
function upperBound(array: number[], value: number, comp: CompareFunction = compare) {
3032
let len = array.length;
3133
let i = 0;
3234

@@ -43,7 +45,7 @@ function upperBound(array, value, comp = compare) {
4345
return i;
4446
}
4547

46-
function lowerBound(array, value, comp = compare) {
48+
function lowerBound(array: number[], value: number, comp: CompareFunction = compare) {
4749
let len = array.length;
4850
let i = 0;
4951

@@ -60,7 +62,7 @@ function lowerBound(array, value, comp = compare) {
6062
return i;
6163
}
6264

63-
function binarySearch(array, value, comp = compare) {
65+
function binarySearch(array: number[], value: number, comp: CompareFunction = compare) {
6466
let cursor = lowerBound(array, value, comp);
6567
return cursor !== array.length && !comp(value, array[cursor]);
6668
}

test/binary-search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
import assert from 'assert'
26-
import { binarySearch } from '../src/index.js'
26+
import { binarySearch } from '../src/index'
2727

2828
describe('binarySearch', () => {
2929
it('less', () => {

test/lower-bound.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
import assert from 'assert'
26-
import { lowerBound } from '../src/index.js'
26+
import { lowerBound } from '../src/index'
2727

2828
describe('lower-bound', () => {
2929
it('less', () => {

test/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
44
"declaration": false,
5-
"noEmit": true
5+
"noEmit": true,
6+
"allowJs": true
67
},
78
"include": [
89
"../src/**/*",
910
"./**/*"
1011
]
11-
}
12+
}

test/upper-bound.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
import assert from 'assert'
26-
import { upperBound } from '../src/index.js'
26+
import { upperBound } from '../src/index'
2727

2828
describe('upper-bound', () => {
2929
it('less', () => {

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"noUnusedParameters": true,
2121
"noImplicitReturns": true,
2222
"noFallthroughCasesInSwitch": true,
23-
"allowJs": true
2423
},
2524
"include": [
2625
"src/**/*"

0 commit comments

Comments
 (0)