UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

22 lines (18 loc) 651 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = sharedStartOfArray; /** * It sorts the array, and then looks just at the first and last items * taken from https://stackoverflow.com/questions/1916218/find-the-longest-common-starting-substring-in-a-set-of-strings * @param {[]} array */ function sharedStartOfArray(array) { const sortedArray = array.concat().sort(); const firstItem = sortedArray[0]; const lastItem = sortedArray[sortedArray.length - 1]; let i = 0; while (i < firstItem.length && firstItem.charAt(i) === lastItem.charAt(i)) i += 1; return firstItem.substring(0, i); }