Trying something different...

The task is to check for strings in A that exist (as substrings) in B, sorted.

%  check for Xs in As that exist in B, in sorted order
in_array(A, B, X) :-
  msort(A, Sorted),
  member(X, Sorted),
  in_b(X, B).
  
in_b(A, B) :-
  member(X, B),
  sub_string(X, _, _, _, A), !.
Code
Diff
  • AbbreviateTwoWords=(s,[a,b,c]=s.split` `)=>a[0]+'.'+b[0]+'. '+c
  • 1
    const AbbreviateTwoWords =(s,[a,b,c]=s.split(' '))=> a[0]+'.'+b[0]+'. '+c
    
    1+
    AbbreviateTwoWords=(s,[a,b,c]=s.split` `)=>a[0]+'.'+b[0]+'. '+c