MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / splitIntoChunks

Function splitIntoChunks

shared/common-utils.ts:82–99  ·  view source on GitHub ↗
(s: string, chunkSize: number)

Source from the content-addressed store, hash-verified

80}
81
82function splitIntoChunks(s: string, chunkSize: number): string[] {
83 const chunks: string[] = [];
84 const isNegative = s.slice(0, 1) === '-';
85 if (isNegative) {
86 s = s.slice(1);
87 }
88 const firstChunkLength = s.length % chunkSize;
89 if (firstChunkLength !== 0) {
90 chunks.push(s.slice(0, firstChunkLength));
91 }
92 for (let i = firstChunkLength; i < s.length; i += chunkSize) {
93 chunks.push(s.slice(i, i + chunkSize));
94 }
95 if (isNegative) {
96 chunks[0] = '-' + (chunks[0] ?? '');
97 }
98 return chunks;
99}
100
101export function addDigitSeparator(n: string, digitSeparator: string, chunkSize: number): string {
102 return splitIntoChunks(n, chunkSize).join(digitSeparator);

Callers 1

addDigitSeparatorFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected