MCPcopy Create free account
hub / github.com/chartjs/Chart.js / _factorize

Function _factorize

src/helpers/helpers.math.ts:41–58  ·  view source on GitHub ↗
(value: number)

Source from the content-addressed store, hash-verified

39 * @private
40 */
41export function _factorize(value: number) {
42 const result: number[] = [];
43 const sqrt = Math.sqrt(value);
44 let i: number;
45
46 for (i = 1; i < sqrt; i++) {
47 if (value % i === 0) {
48 result.push(i);
49 result.push(value / i);
50 }
51 }
52 if (sqrt === (sqrt | 0)) { // if value is a square number
53 result.push(sqrt);
54 }
55
56 result.sort((a, b) => a - b).pop();
57 return result;
58}
59
60/**
61 * Verifies that attempting to coerce n to string or number won't throw a TypeError.

Callers 1

calculateSpacingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected