Skip to content

Commit

Permalink
Add isThird
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreydhuyvetters committed Dec 26, 2018
1 parent e7d199c commit b7b7b51
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -598,6 +598,23 @@ console.log(isTone(getIntervals(['C3', 'D3'])[0]));
// > true;
```

#### + `isThird(interval):boolean`

Returns `true` if the interval is a third (diminished, minor, major or augmented) `(2, 3, 4, 5)`.

```js
import { getIntervals, isThird } from 'music-fns';

console.log(isThird(getIntervals(['C4', 'E4'])[0]));
// > true;

console.log(isThird(getIntervals(['A4', 'C4'])[0]));
// > true;

console.log(isThird(getIntervals(['C4', 'E#4'])[0]));
// > true;
```

#### + `isFifth(interval):boolean`

Returns `true` if the interval is a fifth (diminished, perfect or augmented) `(6, 7, 8)`.
Expand Down
15 changes: 15 additions & 0 deletions src/isThird/index.js
@@ -0,0 +1,15 @@
import { MINOR_THIRD, MAJOR_THIRD } from '../constants/Interval/MinorMajor';
import {
AUGMENTED_THIRD,
DIMINISHED_THIRD
} from '../constants/Interval/AugmentedDiminished';

// @flow

const isThird = (interval: Interval) =>
interval === DIMINISHED_THIRD ||
interval === MINOR_THIRD ||
interval === MAJOR_THIRD ||
interval === AUGMENTED_THIRD;

export default isThird;
31 changes: 31 additions & 0 deletions src/isThird/test.js
@@ -0,0 +1,31 @@
import isThird from './';

describe('isThird', () => {
it('should return true when interval is a diminished third', () => {
expect(isThird(2)).toBe(true);
});

it('should return true when interval is a minor third', () => {
expect(isThird(3)).toBe(true);
});

it('should return true when interval is a major third', () => {
expect(isThird(4)).toBe(true);
});

it('should return true when interval is a augmented third', () => {
expect(isThird(5)).toBe(true);
});

it('should return false when interval is not a third', () => {
expect(isThird(7)).toBe(false);
});

it('should return false when interval is not a third', () => {
expect(isThird(1)).toBe(false);
});

it('should return false on no input', () => {
expect(isThird()).toBe(false);
});
});

0 comments on commit b7b7b51

Please sign in to comment.