Answer the question
In order to leave comments, you need to log in
How to output an empty string?
If you type node file.js <blank string> into the terminal (i.e., don't type anything), you will get an error:
for(let l=str_min.length; l>0; l--){
^
TypeError: Cannot read property 'length' of undefined
function search_largest_substr(){
let str_min = arguments[0];
const list = [];
for(let n=1; n<arguments.length; n++){
if(str_min.length<arguments[n].length){
list.push(arguments[n]);
continue;
}
list.push(str_min);
str_min = arguments[n];
}
for(let l=str_min.length; l>0; l--){
for(let p=0; p<=str_min.length-l; p++){
const substr = str_min.slice(p, p+l);
let isFound = true;
for(let i=0; i<list.length; i++){
if( list[i].indexOf(substr) >= 0)
continue;
isFound=false;
break;
}
if( isFound )
return substr;
}
}
return "";
}
console.log(search_largest_substr.apply(this,process.argv.slice(2)));
Answer the question
In order to leave comments, you need to log in
let str_min = arguments[0] || ""; // по умолчанию пустая строка
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question