MCPcopy Index your code
hub / github.com/nodejs/node / commonPrefix

Function commonPrefix

lib/internal/readline/utils.js:381–397  ·  view source on GitHub ↗
(strings)

Source from the content-addressed store, hash-verified

379
380// This runs in O(n log n).
381function commonPrefix(strings) {
382 if (strings.length === 0) {
383 return '';
384 }
385 if (strings.length === 1) {
386 return strings[0];
387 }
388 const sorted = ArrayPrototypeToSorted(strings);
389 const min = sorted[0];
390 const max = sorted[sorted.length - 1];
391 for (let i = 0; i < min.length; i++) {
392 if (min[i] !== max[i]) {
393 return StringPrototypeSlice(min, 0, i);
394 }
395 }
396 return min;
397}
398
399function reverseString(line, from = '\r', to = '\r') {
400 const parts = StringPrototypeSplit(line, from);

Callers 3

completeOnEditorModeMethod · 0.85
[kTabCompleter]Method · 0.85
showCompletionPreviewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…