Ad

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
    • const AbbreviateTwoWords =(s,[a,b,c]=s.split(' '))=> a[0]+'.'+b[0]+'. '+c
    • AbbreviateTwoWords=(s,[a,b,c]=s.split` `)=>a[0]+'.'+b[0]+'. '+c