Skip to content

Commit 5bff7bb

Browse files
authored
Merge pull request #8 from devvsakib/devvsakib
isJavaScriptFile
2 parents 22cc99d + eaf4a36 commit 5bff7bb

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# 0005 isJavaScriptFile ( L-B )
2+
3+
## Problem
4+
5+
Write a function that returns an new array of true and false values based on the input array. The function should return true if the corresponding element is a JavaScript file.
6+
7+
## Test Cases
8+
9+
- isJavaScriptFile(['L-B.js', 'L-B.css', 'L-B.html', 'L-B.js']); // [true, false, false, true]
10+
- isJavaScriptFile(['L-B.js', 'L-B.js', 'L-B.js', 'L-B.js']); // [true, true, true, true]
11+
- isJavaScriptFile(['L-B.css', 'L-B.css', 'L-B.css', 'L-B.css']); // [false, false, false, false]
12+
13+
## Solution
14+
15+
```javascript
16+
function isJavaScript(file) {
17+
let trueName = [];
18+
for (const ele of file) {
19+
if (ele.endsWith(".js")){
20+
trueName.push(true)
21+
}
22+
else{
23+
trueName.push(false)
24+
}
25+
}
26+
return trueName;
27+
}
28+
29+
const fileInputName = ["javascriptProject.js", "app.js","js.png","clock.java", "image.js"];
30+
const fileName = isJavaScript(fileInputName);
31+
```
32+
33+
## How it works
34+
35+
- The function takes an array as a parameter.
36+
- It creates a variable called trueName and assigns it a value of an empty array.
37+
- It creates a for loop that iterates through the array.
38+
- It checks if the element ends with ".js".
39+
- If it does, it pushes true to the trueName array.
40+
- If it doesn't, it pushes false to the trueName array.
41+
- It returns the value of trueName.
42+
43+
## References
44+
45+
- [Wikipedia](https://en.wikipedia.org/wiki/For_loop)
46+
- [GeeksforGeeks](https://www.geeksforgeeks.org/for-loop-in-javascript/)
47+
- [StackOverflow](https://stackoverflow.com/questions/1669190/javascript-min-max-array-values)
48+
49+
## Problem Added By
50+
51+
- [GitHub](https://www.github.com/devvsakib)
52+
- [LinkedIn](https://www.linkedin.com/in/devvsakib)
53+
- [Twitter](https://twitter.com/devvsakib)
54+
55+
## Contributing
56+
57+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
58+
59+
Please make sure to update tests as appropriate.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function isJavaScript(file) {
2+
let trueName = [];
3+
for (const ele of file) {
4+
if (ele.endsWith(".js")){
5+
trueName.push(true)
6+
}
7+
else{
8+
trueName.push(false)
9+
}
10+
}
11+
return trueName;
12+
}
13+
14+
const fileInputName = ["javascriptProject.js", "app.js","js.png","clock.java", "image.js"];
15+
const fileName = isJavaScript(fileInputName);
16+
console.log(fileName);

0 commit comments

Comments
 (0)