File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
ProblemSolving5/commonCharacters Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Document</ title >
7
+ </ head >
8
+ < body >
9
+ < h1 > Problem Solving 5</ h1 >
10
+ < script src ="commonCharacters.js "> </ script >
11
+ </ body >
12
+ </ html >
Original file line number Diff line number Diff line change
1
+ const commonCharacters = ( str1 , str2 ) => {
2
+ let result = [ ] ;
3
+ for ( let i = 0 ; i < str1 . length ; i ++ ) {
4
+ let found = false ;
5
+ for ( let j = 0 ; j < str2 . length ; j ++ ) {
6
+ if ( str1 [ i ] == str2 [ j ] )
7
+ {
8
+ found = true ;
9
+ break ;
10
+ }
11
+ }
12
+ if ( found && ! result . includes ( str1 [ i ] ) )
13
+ result . push ( str1 [ i ] ) ;
14
+ }
15
+ return result . join ( '' ) ;
16
+ } ;
17
+ console . log ( commonCharacters ( 'acexivou' , 'aegihobu' ) ) ; // it must return aeiou
You can’t perform that action at this time.
0 commit comments