I was woking on a problem and got stuck and how I should validate a given string input. Here is the original question
I think my approach is ok but I'm stuck on what to do now.
here is my attempt so far:
const solution =(S)=>{
let validParams = {
'--count': '--count',
'--name': '--name',
'--help': '--help'
}
let strToTest;
for(k of validParams){
switch (S.includes(k)) {
case '--help':
return 1
case '--count':
strToTest = parseInt(S.replace(/--count/g,''))
return countValidator(strToTest);
case '--name':
strToTest = S.replace(/--count/g,'')
return nameValidator(strToTest);
default:
return 1
}
}
}
const countValidator = (num) =>{
if(num > 10 && num < 100){
return 0
}
}
const nameValidator = (str) =>{
if(str.length > 3 && str.length < 10){
return 0
}
}
Here the test cases I saw as well:
solution('--count g') // -1
solution('-help name') // -1
solution('--name SOME_NAME --COUNT 10') // 0
solution('--count 44') // 0

caseshouldn't be a boolean expression. It's a string that will be compared withS. Useif/else if/elseto perform other kinds of tests.if/else. can you explain