Write a function commonCharacters(s1, s2) that finds the letters that occur in both strings: their intersection.
s1 and s2 are strings. They can be empty and can have spaces, digits and punctuation.a-z count. Spaces, digits and other characters are never in the result. Letters with accents, like é, are not in a-z and do not count either.'J' in one string and 'j' in the other is a common letter.A Set of the letters of each string makes this short.
commonCharacters('Java With Collections', 'Java Selenium')Returns [ 'a', 'e', 'i', 'j', 'l', 'n', 's', 'v' ]
commonCharacters('Hello', 'World')Returns [ 'l', 'o' ]
commonCharacters('abc', 'xyz')Returns []
Asked at Synechron · Source
commonCharacters('Java With Collections', 'Java Selenium')[
'a', 'e', 'i',
'j', 'l', 'n',
's', 'v'
]commonCharacters('Hello', 'World')[ 'l', 'o' ]commonCharacters('abc', 'xyz')[]Hidden tests run on Submit.