fe-interview
                                
                                
                                
                                    fe-interview copied to clipboard
                            
                            
                            
                        [js] 第815天 写一个方法将把true和false转为1和0
 Number(true)
function(bool){
return  bool ? 1:0
}
                                    
                                    
                                    
                                
+true     // 1
+false    // 0
                                    
                                    
                                    
                                
const toNumber= (res)=>+res;
function fn(bol) { let bol2 = [] if (typeof bol === "boolean") { return Number(bol) }else{ bol.map((item,index)=>{ if (bol[index]) { bol2.push(1) }else{ bol2.push(0) } }) } return bol2 }
Number(true)//1 Number(false)//0
function convert(params){ if(typeof params == "boolean"){ if(params == true || params == false){ console.log(Number(params)) } } } convert(false)
Number