Skip to content

Commit 6b39cb9

Browse files
Proof of concept with Fibonacci numbers
1 parent 678ebe6 commit 6b39cb9

9 files changed

+225
-10
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
[@aureooms/js-integer-sequences](https://aureooms.github.io/js-integer-sequences)
22
==
33

4+
<img src="http://www.polprimos.com/imagenespub/poldiv13.jpg" width="864">
5+
46
Integer sequences for JavaScript.
57
See [docs](https://aureooms.github.io/js-integer-sequences/index.html).
8+
Parent is [@aureooms/js-algorithms](https://github.com/aureooms/js-algorithms).
9+
10+
```js
11+
import { list , map } from '@aureooms/js-itertools' ;
12+
import * as integer from '@aureooms/js-number' ;
13+
14+
let F = new Fibonacci( integer ) ;
15+
list( map ( integer.stringify , F.range( 10 ) ) ) ; // 0 1 1 2 3 5 8 13 21 34
16+
```
617

718
[![License](https://img.shields.io/github/license/aureooms/js-integer-sequences.svg?style=flat)](https://raw.githubusercontent.com/aureooms/js-integer-sequences/master/LICENSE)
819
[![NPM version](https://img.shields.io/npm/v/@aureooms/js-integer-sequences.svg?style=flat)](https://www.npmjs.org/package/@aureooms/js-integer-sequences)
@@ -14,3 +25,8 @@ See [docs](https://aureooms.github.io/js-integer-sequences/index.html).
1425
[![NPM downloads per month](https://img.shields.io/npm/dm/@aureooms/js-integer-sequences.svg?style=flat)](https://www.npmjs.org/package/@aureooms/js-integer-sequences)
1526
[![GitHub issues](https://img.shields.io/github/issues/aureooms/js-integer-sequences.svg?style=flat)](https://github.com/aureooms/js-integer-sequences/issues)
1627
[![Documentation](https://aureooms.github.io/js-integer-sequences/badge.svg)](https://aureooms.github.io/js-integer-sequences/source.html)
28+
29+
## Children
30+
31+
- [@aureooms/js-fibonacci](https://github.com/aureooms/js-fibonacci): Fibonacci numbers for JavaScript.
32+

lib/Fibonacci.js

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/IntegerSequence.js

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,28 @@
2222
"bugs": {
2323
"url": "https://github.com/aureooms/js-integer-sequences/issues"
2424
},
25-
"dependencies": {},
25+
"dependencies": {
26+
"@aureooms/js-error": "^3.0.0",
27+
"@aureooms/js-fibonacci": "^3.1.0",
28+
"@aureooms/js-itertools": "^3.2.1"
29+
},
2630
"devDependencies": {
27-
"ava": "^0.16.0",
28-
"babel-cli": "^6.18.0",
29-
"babel-polyfill": "^6.16.0",
30-
"babel-preset-latest": "^6.16.0",
31-
"codeclimate-test-reporter": "^0.4.0",
32-
"coveralls": "^2.11.14",
33-
"esdoc": "^0.4.8",
34-
"nyc": "^8.4.0"
31+
"@aureooms/js-number": "^3.0.0",
32+
"ava": "^0.19.1",
33+
"babel-cli": "^6.24.1",
34+
"babel-polyfill": "^6.23.0",
35+
"babel-preset-latest": "^6.24.1",
36+
"codeclimate-test-reporter": "^0.4.1",
37+
"coveralls": "^2.13.0",
38+
"esdoc": "^0.5.2",
39+
"nyc": "^10.2.0"
3540
},
3641
"homepage": "https://aureooms.github.io/js-integer-sequences",
37-
"keywords": ["computer-science", "integer-sequences", "mathematics"],
42+
"keywords": [
43+
"computer-science",
44+
"integer-sequences",
45+
"mathematics"
46+
],
3847
"license": "AGPL-3.0",
3948
"main": "lib/index.js",
4049
"repository": {

src/Fibonacci.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { IntegerSequence } from './IntegerSequence' ;
2+
import { __generator__ } from '@aureooms/js-fibonacci' ;
3+
4+
export class Fibonacci extends IntegerSequence {
5+
6+
all ( ) {
7+
8+
const { iadd , $0 , $1 } = this.integer ;
9+
const generator = __generator__( iadd , $0 , $1 ) ;
10+
const F = generator( ) ;
11+
return F ;
12+
13+
}
14+
15+
}

src/IntegerSequence.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { last , take , drop } from '@aureooms/js-itertools' ;
2+
import { NotImplementedError } from '@aureooms/js-error' ;
3+
4+
export class IntegerSequence {
5+
6+
constructor ( integer ) {
7+
8+
this.integer = integer ;
9+
10+
}
11+
12+
nth ( n ) {
13+
14+
return last( this.range( n + 1 ) ) ;
15+
16+
}
17+
18+
range ( i , j ) {
19+
20+
if ( j === undefined ) return take( this.all( ) , i ) ;
21+
22+
return drop( take( this.all( ) , j ) , i ) ;
23+
24+
}
25+
26+
all ( ) {
27+
28+
throw NotImplementedError('IntegerSequence#all is not implemented.') ;
29+
30+
}
31+
32+
}

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './Fibonacci' ;
2+
export * from './IntegerSequence' ;

test/src/Fibonacci.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import test from 'ava' ;
2+
3+
import * as integer from '@aureooms/js-number' ;
4+
import { list , map } from '@aureooms/js-itertools' ;
5+
import { Fibonacci } from '../../src' ;
6+
7+
test( 'Fibonacci' , t => {
8+
9+
const F = new Fibonacci( integer ) ;
10+
11+
const n = 10 ;
12+
const a = [ "0" , "1" , "1" , "2" , "3" , "5" , "8" , "13" , "21" , "34" ] ;
13+
14+
t.deepEqual( list( map ( integer.stringify , F.range( n ) ) ) , a ) ;
15+
16+
t.deepEqual( integer.stringify( F.nth( 0 ) ) , "0" ) ;
17+
t.deepEqual( integer.stringify( F.nth( 38 ) ) , "39088169" ) ;
18+
19+
} ) ;

0 commit comments

Comments
 (0)