Javascript OR and AND operators

Hi, I’m trying to create the object where keys are numbers and values are the array of alphabets as per the old keypad mobile.

Here is the code I have written

let phoneNumber = function (){

     let alpha =[..."abcdefghijklmnopqrstuvwxyz"];

     let obj = {};

     let array=[];

     function innerRecursion(count=2, index=0){

        if(index>25){

            return obj;

        }else{

            if((array.length===3) && array[0]!=="p" && array[0]!=="q"){

                console.log(array[0]);

                obj[count]=array;

                array = [];

                count++;

                innerRecursion(count, index);

            }

            else if((array.length===3) && (array[0]==="p" || array[0]==="q")){

                console.log("yerripappa", count);

                array.push(alpha[index]);

                obj[count]=array;

                array = [];

                count++;

                index++;

                innerRecursion(count, index);

            }

           

            else{

                array.push(alpha[index]);

                index++;

                innerRecursion(count, index);

            }

        }

     } innerRecursion(); return obj;

 }

The output I’m getting is
{
2:[‘a’,‘b’,‘c’]
3.: [‘d’, ‘e’, ‘f’]
4.: [‘g’, ‘h’, ‘i’]
5: [‘j’, ‘k’, ‘l’]
6.: [‘m’, ‘n’, ‘o’]
7: [‘p’, ‘q’, ‘r’, ‘s’]
8: [‘t’, ‘u’, ‘v’]
9: [‘w’, ‘x’, ‘y’]
}
But I expect to get the last key 9 to be 9:[‘w’, ‘x’, ‘y’,‘z’];

But I don’t know where Iam making the mistake. Please help thanks in advance

From just a quick glance I’d say that problem in in else statement - [‘w’, ‘x’, ‘y’] matches that statement. I guess you should see also in the console printed letter w.

I think at this line (and another similar line a little lower) the “q” should be “w”

Thank you so much for your help. I’m a little late to thankyou.

I hope you’re doing good my friend.

Happy coding :heart_eyes:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.