• + 0 comments

    JavaScript

    function birthday(s, d, m) {
        
        let ways=0;
        
        for(let i=0;i<s.length;i++){
            
            if(s.length>1){
            let cut_slice=s.slice(i,m);
            m+=1;
                    
            let sum_of_cut_slice=0;
            
            for(let j=0;j<cut_slice.length;j++){
                sum_of_cut_slice+=cut_slice[j];
                }
                
            if(sum_of_cut_slice==d){
                ways+=1;
                }
                
            }
            
            else{
                if(s[0]==d){
                ways+=1;    
                }
            }
        }
        
        return ways;
    
    }