https://www.codewars.com/kata/550554fd08b86f84fe000a58
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.
Example 1:
a1 = ["arp", "live", "strong"]
a2 = ["lively", "alive", "harp", "sharp", "armstrong"]
returns ["arp", "live", "strong"]
Example 2:
a1 = ["tarp", "mice", "bull"]
a2 = ["lively", "alive", "harp", "sharp", "armstrong"]
returns []
Notes:
- Arrays are written in "general" notation. See "Your Test Cases" for examples in your language.
- In Shell bash a1 and a2 are strings. The return is a string where words are separated by commas.
- Beware: In some languages r must be without duplicates.
코드
function inArray(array1,array2){
let result = [];
for(let i = 0; i < array1.length; i++){
let check = false;
for(let j = 0; j < array2.length; j++){
if(array2[j].includes(array1[i])){
check = true;
break;
}
}
if(check) result.push(array1[i]);
}
return result.sort();
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Remove the minimum (7 kyu) / JavaScript (0) | 2023.02.17 |
---|---|
[Codewars] Do I get a bonus? (8 kyu) / JavaScript (0) | 2023.02.16 |
[Codewars] Break camelCase (6 kyu) / JavaScript (0) | 2023.02.14 |
[Codewars] Grasshopper - Grade book (8 kyu) / JavaScript (0) | 2023.02.13 |
[Codewars] Rot13 (5 kyu) / JavaScript (0) | 2023.02.12 |
댓글