Skip to content

Commit 8cc31bf

Browse files
authored
readme updated
updated readme as Guidelines
1 parent b92a9e3 commit 8cc31bf

File tree

1 file changed

+54
-15
lines changed

1 file changed

+54
-15
lines changed

L-B/0014 stringCheck/README.md

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,55 @@
1-
## 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.
2-
### eg: stringCheck(["React","cat"]) should return true
3-
### stringCheck(["tab","tan"]) should return false
4-
5-
# Explanation
6-
## first create a function that takes an array as argument.
7-
## create a variables 'flag' with a value of zero.
8-
## create two variables string1 and string2 from the first and second element of the array.
9-
### eg: let myArray=["cat","dog"]
10-
### let string1=myArray[0] that is "cat"
11-
### let string2=myArray[1] that is "dog"
12-
### 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.
13-
14-
## Problem added by
15-
### Fais Edathil [Git Hub](https://github.com/E-fais)
1+
# 0014 stringCheck ( L-B )
162

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.

0 commit comments

Comments
 (0)