Skip to content

Commit

Permalink
Merge branch 'master' into taras-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
taras committed Oct 23, 2018
2 parents 813506b + 016aab3 commit 00a3dff
Show file tree
Hide file tree
Showing 6 changed files with 978 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
.esm-cache
/dist
.nyc_output/
coverage
package-lock.json
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ install:
- npm install -g coveralls
- npm install

after_success: npm run coverage

script:
- npm test

Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"repository": "git+ssh://git@github.com/microstates/microstates.js.git",
"scripts": {
"start": "node repl.js",
"test": "mocha --recursive -r tests/setup tests",
"test": "nyc --reporter=html --reporter=text mocha --recursive -r tests/setup tests",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"build": "rollup -c",
"bench": "node -r ./tests/setup benchmarks/index.js",
"prepare": "npm run build",
Expand All @@ -49,7 +50,14 @@
"rxjs": "^6.2.1"
},
"dependencies": {
"coveralls": "3.0.2",
"funcadelic": "^0.5.0",
"nyc": "13.1.0",
"symbol-observable": "^1.2.0"
},
"nyc": {
"exclude": [
"**/tests"
]
}
}
6 changes: 6 additions & 0 deletions src/types/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export default parameterized(T => class ArrayType {
return [value, ...valueOf(this)];
}

sort(compareFn) {
let init = valueOf(this);
let result = [...init].sort(compareFn);
return init.every((member, idx) => result[idx] === member) ? this : result;
}

filter(fn) {
let list = valueOf(this);
let result = list.filter((member) => fn(create(T, member)));
Expand Down
17 changes: 17 additions & 0 deletions tests/types/array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ describe("ArrayType", function() {
});
});

describe("sort", () => {
let sorted;

beforeEach(() => {
let unsorted = create([String], ["c", "b", "a"]);
sorted = unsorted.sort();
});

it("has a value that is the sorted version of the original value", () => {
expect(valueOf(sorted)).toEqual(["a", "b", "c"]);
});

it("returns the same array microstate if all of the values in the underlying array remains the same", () => {
expect(sorted.sort()).toBe(sorted);
});
});

describe("filter", () => {
let filtered;

Expand Down
Loading

0 comments on commit 00a3dff

Please sign in to comment.