Skip to content

Commit 8f88c88

Browse files
init with gulp.js
1 parent 68cd5f0 commit 8f88c88

File tree

7 files changed

+78
-0
lines changed

7 files changed

+78
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ typings/
5959

6060
# next.js build output
6161
.next
62+
.idea/
63+

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# algorithmInJS
22

33
Encapsulate the collection of commonly used algorithms for node.js
4+

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('dist/index')

src/greet.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function sayHello(name: string) {
2+
return `Hello from ${name}`;
3+
}

src/lib/LinkedList.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export class LinkedList {
2+
public name:string;
3+
constructor(name:string){
4+
this.name = name
5+
}
6+
/**
7+
* @param a {Array} Array of a
8+
* @param n {Number} array length of a
9+
* @param key {Number} the key you want to find
10+
* */
11+
public findKeyInArray(a: number[], n: number, key: any): number {
12+
if (a == null || n <= 0) {
13+
return -1
14+
}
15+
let i = 0
16+
while (i < n) {
17+
if (a[i] == key) {
18+
return i
19+
}
20+
i++
21+
}
22+
return -1
23+
}
24+
/**
25+
* @param a {Array} Array of a
26+
* @param n {Number} array length of a
27+
* @param key {Number} the key you want to find
28+
* */
29+
public findKeyInArrayRapidlly(a: number[], n: number, key: any):number{
30+
if (a == null || n <= 0) {
31+
return -1
32+
}
33+
if(a[n-1]==key) {
34+
return n-1
35+
}
36+
let tmp:number = a[n-1]
37+
a[n-1] = key
38+
let i = 0
39+
while (a[i]!=key) {
40+
++i
41+
}
42+
a[n-1] = tmp;
43+
if(i = n-1) {
44+
return -1
45+
}
46+
else{
47+
return i
48+
}
49+
}
50+
}

src/lib/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
version:'1.0.0'
3+
}

test/index.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var assert = require('chai').assert
2+
var should = require('chai').should()
3+
var expect = require('chai').expect
4+
var {LinkedList} = require('../dist/lib/LinkedList')
5+
console.log(LinkedList)
6+
describe('LinkedList test',function () {
7+
this.timeout(3000);
8+
it('it should output the key ',function (done) {
9+
var a = [4,2,3,5,9,6]
10+
var n = 6
11+
var key = 6
12+
var linkedList = new LinkedList('小米')
13+
var result = linkedList.findKeyInArrayRapidlly(a,n,key)
14+
console.log(result)
15+
expect(result).to.be.a('number')
16+
done()
17+
})
18+
})

0 commit comments

Comments
 (0)