From 4c4803745410d2d0eab4bbd59d22719d99f9cc7b Mon Sep 17 00:00:00 2001 From: Jonas Drieghe Date: Tue, 13 Nov 2018 21:09:55 +0100 Subject: [PATCH 1/2] Add isMajorScale function --- src/isMajorScale/index.js | 27 +++++++++++++++++++++++++++ src/isMajorScale/test.js | 18 ++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/isMajorScale/index.js create mode 100644 src/isMajorScale/test.js diff --git a/src/isMajorScale/index.js b/src/isMajorScale/index.js new file mode 100644 index 0000000..cff2d50 --- /dev/null +++ b/src/isMajorScale/index.js @@ -0,0 +1,27 @@ +// @flow + +import isDiatonicScale from '../isDiatonicScale'; +import normalizeScale from '../normalizeScale'; +import getIntervals from '../getIntervals'; +import IONIAN from '../constants/Mode/IONIAN'; + +type options = { + direction?: direction +}; + +const isMajorScale = (scale: Scale, { direction = 1 }: options = {}) => { + if (![-1, 1].includes(direction)) { + throw new Error('Direction should be 1 (up) or -1 (down)'); + } + + if (!isDiatonicScale(scale)) return false; + + if (direction === -1) scale.reverse(); + + const normalizedScale = normalizeScale(scale); + const intervals = getIntervals(normalizedScale); + + return IONIAN.join(',') === intervals.join(','); +}; + +export default isMajorScale; diff --git a/src/isMajorScale/test.js b/src/isMajorScale/test.js new file mode 100644 index 0000000..cdf6b0f --- /dev/null +++ b/src/isMajorScale/test.js @@ -0,0 +1,18 @@ +// https://en.wikipedia.org/wiki/Major_scale + +import isMajorScale from './'; + +describe('isMajorScale', () => { + it('should return true on major scale ', () => { + const scale = ['C', 'D', 'E', 'F', 'G', 'A', 'B']; + expect(isMajorScale(scale)).toBe(true); + }); + it('should return true on major scale', () => { + const scale = ['C1', 'D1', 'E1', 'F1', 'G1', 'A1', 'B1']; + expect(isMajorScale(scale)).toBe(true); + }); + it('should return false on minor scale ', () => { + const scale = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; + expect(isMajorScale(scale)).toBe(false); + }); +}); From 21d5f262909dc76bd75ca5fac5ea4f72f964ab4c Mon Sep 17 00:00:00 2001 From: Jonas Drieghe Date: Tue, 13 Nov 2018 21:17:49 +0100 Subject: [PATCH 2/2] Add isMinorScale --- src/isMinorScale/index.js | 27 +++++++++++++++++++++++++++ src/isMinorScale/test.js | 18 ++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/isMinorScale/index.js create mode 100644 src/isMinorScale/test.js diff --git a/src/isMinorScale/index.js b/src/isMinorScale/index.js new file mode 100644 index 0000000..2e8c45a --- /dev/null +++ b/src/isMinorScale/index.js @@ -0,0 +1,27 @@ +// @flow + +import isDiatonicScale from '../isDiatonicScale'; +import normalizeScale from '../normalizeScale'; +import getIntervals from '../getIntervals'; +import AEOLIAN from '../constants/Mode/AEOLIAN'; + +type options = { + direction?: direction +}; + +const isMinorScale = (scale: Scale, { direction = 1 }: options = {}) => { + if (![-1, 1].includes(direction)) { + throw new Error('Direction should be 1 (up) or -1 (down)'); + } + + if (!isDiatonicScale(scale)) return false; + + if (direction === -1) scale.reverse(); + + const normalizedScale = normalizeScale(scale); + const intervals = getIntervals(normalizedScale); + + return AEOLIAN.join(',') === intervals.join(','); +}; + +export default isMinorScale; diff --git a/src/isMinorScale/test.js b/src/isMinorScale/test.js new file mode 100644 index 0000000..1d87aa8 --- /dev/null +++ b/src/isMinorScale/test.js @@ -0,0 +1,18 @@ +// https://en.wikipedia.org/wiki/Minor_scale + +import isMinorScale from './'; + +describe('isMinorScale', () => { + it('should return true on minor scale ', () => { + const scale = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; + expect(isMinorScale(scale)).toBe(true); + }); + it('should return true on minor scale', () => { + const scale = ['A1', 'B1', 'C2', 'D2', 'E2', 'F2', 'G2']; + expect(isMinorScale(scale)).toBe(true); + }); + it('should return false on major scale ', () => { + const scale = ['C', 'D', 'E', 'F', 'G', 'A', 'B']; + expect(isMinorScale(scale)).toBe(false); + }); +});