Better check required

Tell us what’s happening:

There are multiple answers to this problem. please use eval to find the correct answer

Your code so far


function solve24 (numStr) {
 // Good luck!
 //thank you
 //let num = 2222;
//while(num<2250){

 //numStr=num.toString();
 console.log('q: '+numStr);
 let arr = getall(numStr,0,numStr.length);
//console.log(arr);
let signs = getall('+-*/',1,3);
//console.log(signs);

let barray=[['(','',')','','',''],['(','',')','(','',')'],['(','','','',')',''],['','(','','',')',''],['','(','','','',')'],['','','','(','',')'],['','','','','','']];
let farray =[];
let ans='';
arr.map(u=>{
 let go = true;
 if(true){
signs.map(v=>{
 
barray.map(w=>{
 let calc;
 if((v.indexOf('*')==-1&&v.indexOf('/')==-1)||(v[0]==v[1]&&v[1]==v[2])){
calc = [u[0],v[0],u[1],v[1],u[2],v[2],u[3]];
 }else{
calc = [w[0],u[0],v[0],w[1],u[1],w[2],v[1],w[3],u[2],w[4],v[2],u[3],w[5]];
 }
let calcstring = calc.join('');
//console.log(calcstring);
if(eval(calcstring)==24){
 if(farray.indexOf(calcstring)==-1){
 farray.push(calcstring);
console.log('ans'+calcstring);
 }
 ans=calcstring;
go=false;

return calcstring;
}

});
});
 }
});

//return ans;
console.log('no of ways to solve: '+farray.length);
return ans;
//num++;
//}
}


function getall(numStr,style,max){
 numStr=numStr.split('');
let nStr = Array(numStr.length).fill(0,0).map((u,i)=>u=i).join('');
 //console.log(nStr);
 let arr=nStr.split('').map(u=>u=[u]);
 let oarr=nStr.split('');
 let ct = 0;
 let oarray;
 while(ct<max-1){
   let farray=[];
 //console.log(arr);
 let narr=arr.map(v=>{
   let toadd;
   if(style==0){
   toadd = oarr.filter(w=>v.indexOf(w)==-1);
   }else{
   toadd =[...oarr];
   }
   //console.log(toadd);
   let nadd = toadd.map(x=>x=[...v,...x]);
   
   v = [...nadd];
   farray=[...farray,...nadd]
   return v;
 });
 
arr=farray;


ct++;
}


let numarr = arr.map(u=>{
 return u.map(v=> {
   return numStr[parseInt(v)];
 });
});

 return numarr;
}













//


//




//

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; GM1911) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36.

Challenge: 24 game

Link to the challenge:

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.