Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a return #5

Open
c3ho opened this issue Sep 25, 2020 · 2 comments
Open

Add a return #5

c3ho opened this issue Sep 25, 2020 · 2 comments

Comments

@c3ho
Copy link

c3ho commented Sep 25, 2020

lFinder/bin/index.js

Lines 36 to 57 in 59729ee

if (err) {
console.log(err);
} else {
//Goes through entered file and puts each line into an element inside "lineArray"
lineArray = data.toString().split("\n");
console.log("Number of lines in file is: ", lineArray.length, "\n");
//goes through "lineArray" and uses the filter method to find lines with http and https in them.
//Also removes lines that do NOT have urls in them so that we wont wate time on those using our regex on them.
//Then puts the lines with http and https (with all capitals too) in "lineWithURLArray"
lineWithURLArray = lineArray.filter(line => line.includes("https:") || line.includes("http:") || line.includes("HTTPS:") || line.includes("HTTP:"));
console.log("The number of lines with URLs in this file: ", lineWithURLArray.length, "\n");
console.log("Checking for the number of URL's in this file...\n")
//goes through the "lineWithURLArray" and finds things that match the regex. Then puts them into onlyURLArray made at line 21-ish
for (let i = 0; i < lineWithURLArray.length; i++) {
let res = lineWithURLArray[i].match(regexForURLs);
if (res) {
onlyURLArray = onlyURLArray.concat(res);
}
};

If you add a return after line 37. You can skip on using the else allowing you to use const lineArray

@Supercraft888
Copy link
Owner

I'm sorry could you please explain this a bit more, I'm a tad bit confused

@c3ho
Copy link
Author

c3ho commented Sep 30, 2020

if (err) { 
   console.log(err); 
   return<----------------- Added new line, this function just returns and we don't go further if there's an err
 } else { <----------------- You won't need this else line since if there's an err it'll return
 //Goes through entered file and puts each line into an element inside "lineArray" 
 const lineArray = data.toString().split("\n"); <--- You don't have to declare this at line 19 and instead declare it here
 console.log("Number of lines in file is: ", lineArray.length, "\n"); 
  
 //goes through "lineArray" and uses the filter method to find lines with http and https in them. 
 //Also removes lines that do NOT have urls in them so that we wont wate time on those using our regex on them. 
 //Then puts the lines with http and https (with all capitals too) in "lineWithURLArray"  
 lineWithURLArray = lineArray.filter(line => line.includes("https:") || line.includes("http:") || line.includes("HTTPS:") || line.includes("HTTP:")); 
 console.log("The number of lines with URLs in this file: ", lineWithURLArray.length, "\n"); 
  
 console.log("Checking for the number of URL's in this file...\n") 
  
 //goes through the "lineWithURLArray" and finds things that match the regex.  Then puts them into onlyURLArray made at line 21-ish 
 for (let i = 0; i < lineWithURLArray.length; i++) { 
   let res = lineWithURLArray[i].match(regexForURLs); 
   if (res) { 
     onlyURLArray = onlyURLArray.concat(res); 
   } 
 }; 

Actually a few of your variables could be declared inside your function instead of being a global variable, but that's for another issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants