Skip to content

Commit 245983a

Browse files
authored
Merge pull request #26 from E-fais/main
Add a new problem.
2 parents 5ec0a45 + 8cc31bf commit 245983a

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

L-B/0014 stringCheck/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# 0014 stringCheck ( L-B )
2+
3+
## Problem
4+
5+
You are given an array with two strings. Write a function to check all the letters present in the second string is also present in the first string, ignoring the case. The function should return a boolean.
6+
7+
## Test Cases
8+
9+
- Input: ['hello', 'hey'], Output: false
10+
- Input: ['hello', 'hello'], Output: true
11+
- Input: ['React', 'cat'], Output: true
12+
13+
## Solution
14+
15+
```javascript
16+
17+
function stringCheck(arr){
18+
let string1 = arr[0].toLowerCase()
19+
let string2 = arr[1].toLowerCase()
20+
let flag = 0
21+
for (let i = 0 ; i < string2.length; i++){
22+
if(!string1.includes(string2[i])){
23+
flag += 1
24+
}
25+
}
26+
return flag > 0 ? false : true
27+
}
28+
29+
console.log(stringCheck(arr))
30+
31+
```
32+
33+
## How it works
34+
35+
- First create a function that takes an array as argument.
36+
- Create a variables 'flag' with a value of zero.
37+
- Create two variables string1 and string2 from the first and second element of the array.
38+
- Loop through each letters of string2 with a for loop and check the letters present in string1 by a ".includes()" function in javascript.If any of the letter in string2 is not present in string1 we have to add 1 to our 'flag' variable.Finally we use if condition to check the flag variable.If flag is zero that means all the letters of the string2 are present in string1, and return true. if flag is greater than zero , that means some letters are not present, so we retun false.
39+
40+
41+
## References
42+
43+
- [Array.prototype.includes()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
44+
- [String.prototype.toLowerCase()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
45+
46+
## Problem Added By
47+
48+
- [GitHub](https://github.com/E-fais)
49+
50+
51+
## Contributing
52+
53+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
54+
55+
Please make sure to update tests as appropriate.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function stringCheck(arr){
2+
let string1=arr[0].toLowerCase()
3+
let string2=arr[1].toLowerCase()
4+
let flag=0
5+
for (let i=0 ; i<string2.length;i++){
6+
if(!string1.includes(string2[i])){
7+
8+
flag+=1
9+
}
10+
}
11+
12+
if(flag>0){
13+
return false
14+
}else{
15+
return true
16+
}
17+
}

0 commit comments

Comments
 (0)