-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
98 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
import { NumberArray } from 'cheminfo-types'; | ||
import { DataXY, NumberArray } from 'cheminfo-types'; | ||
import { isAnyArray } from 'is-any-array'; | ||
/** | ||
* Check that x and y are arrays with the same length. | ||
* @param x - first array | ||
* @param y - second array | ||
* @throws if x or y are not the same length, or if they are not arrays | ||
*/ | ||
export default function checkArrayLength(x: NumberArray[], y: NumberArray) { | ||
if ((!isAnyArray(x) && !isAnyArray(x[0])) || !isAnyArray(y)) { | ||
throw new TypeError('x and y must be arrays'); | ||
export default function checkArrayLength(input: DataXY, output: NumberArray) { | ||
if (!isAnyArray(input.x) || !isAnyArray(input.y) || !isAnyArray(output)) { | ||
throw new TypeError('x, y and outputs must be arrays'); | ||
} | ||
if (x[0].length < 2) { | ||
if (input.x.length < 2) { | ||
throw new RangeError( | ||
'explanatory variable should be two element per point', | ||
); | ||
} | ||
|
||
if (x.length !== y.length) { | ||
if (input.x.length !== input.y.length) { | ||
throw new RangeError('x and y data must have the same length'); | ||
} | ||
|
||
if (input.x.length !== output.length) { | ||
throw new RangeError('input and outputs must have the same length'); | ||
} | ||
} |