File tree 7 files changed +78
-0
lines changed
7 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -59,3 +59,5 @@ typings/
59
59
60
60
# next.js build output
61
61
.next
62
+ .idea /
63
+
Original file line number Diff line number Diff line change 1
1
# algorithmInJS
2
2
3
3
Encapsulate the collection of commonly used algorithms for node.js
4
+
Original file line number Diff line number Diff line change
1
+ module . exports = require ( 'dist/index' )
Original file line number Diff line number Diff line change
1
+ export function sayHello ( name : string ) {
2
+ return `Hello from ${ name } ` ;
3
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ export default {
2
+ version :'1.0.0'
3
+ }
Original file line number Diff line number Diff line change
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
+ } )
You can’t perform that action at this time.
0 commit comments