Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

16
LINES

< > BotCompany Repo | #1014380 // commonPrefixCI

JavaX fragment (include)

1  
static S commonPrefixCI(S a, S b) {
2  
  int i = 0, nb = b.length(), na = a.length(), n = min(na, nb);
3  
  while (i < n && eqic(a.charAt(i), b.charAt(i)))
4  
    ++i;
5  
  return i == nb ? b : substring(a, 0, i);
6  
}
7  
8  
static S commonPrefixCI(L<S> l) {
9  
  if (empty(l)) ret "";
10  
  S s = first(l);
11  
  for (int i = 1; i < l(l); i++) {
12  
    if (empty(s)) ret s;
13  
    s = commonPrefixCI(s, l.get(i));
14  
  }
15  
  ret s;
16  
}

Author comment

Began life as a copy of #1013590

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1014380
Snippet name: commonPrefixCI
Eternal ID of this version: #1014380/4
Text MD5: 1cfd7e70f20eb536b48e0449fc308693
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-20 17:31:09
Source code size: 407 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 360 / 404
Version history: 3 change(s)
Referenced in: [show references]