Skip to content

Commit

Permalink
feat: allow {x:[], y:[]} for peaks definition
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Nov 23, 2022
1 parent 7171b27 commit bb6d261
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/__tests__/checkPeaks.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { test, expect } from 'vitest';

import { checkPeaks } from '../checkPeaks.js';

test('object', () => {
const result = checkPeaks({ x: [1, 2, 3], y: [2, 3, 4] });
expect(result).toStrictEqual([
[1, 2, 3],
[2, 3, 4],
]);
});

test('correct array', () => {
const result = checkPeaks([
[1, 2, 3],
[2, 3, 4],
]);
expect(result).toStrictEqual([
[1, 2, 3],
[2, 3, 4],
]);
});

test('array of [x,y]', () => {
const result = checkPeaks([
[1, 2],
[2, 3],
[3, 4],
]);
expect(result).toStrictEqual([
[1, 2, 3],
[2, 3, 4],
]);
});
3 changes: 3 additions & 0 deletions src/checkPeaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export function checkPeaks(peaks) {
if (Array.isArray(peaks) && Array.isArray(peaks[0]) && peaks.length === 2) {
return peaks;
}
if (Array.isArray(peaks.x) && Array.isArray(peaks.y)) {
return [peaks.x, peaks.y];
}
const x = new Array(peaks.length);
const y = new Array(peaks.length);
for (let i = 0; i < peaks.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const COMMON_BOTH = 3;

/**
* A number, or a string containing a number.
* @typedef {([number[],number[]]|[number,number][])} Peaks
* @typedef {([number[],number[]]|[number,number][]|{x:number[],y:number[]})} Peaks
*/

/**
Expand Down

0 comments on commit bb6d261

Please sign in to comment.