Solve Sock Merchant (A tad stuck on this. Im a newbie. forgive me :)

function findPairs(ar, find, pairs) {
     if (ar.length > 0) {
          let newArr = ar;
          
          if (newArr.indexOf(find) > -1) {
                pairs++; 
               newArr = [ ...newArr.slice(0, newArr.indexOf(find)),
               ...newArr.slice(newArr.indexOf(find) + 1)];
          }
          return findPairs(
               newArr.slice(1),
               newArr[0],
               pairs
          );
     }

     return pairs;
}
function sockMerchant(n, ar) {
     const min = 1;
     const max = 100;
      
     ar = (typeof ar === "string") ? ar.split(' ') : ar;
 
     if (arar.length >= min
          && ar.length <= max
          && n === parseInt(n, 0)
          && n >= min
          && n <= max 
          && n === ar.length) {
               return findPairs(ar.slice(1), ar[0], 0);
     }
     
     // if does not meet criteria return 0
     return 0; 
}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums


You need to give us more to go on than just your code. What’s going on? What is your code supposed to do? What problems are you having? What else have you tried? How can someone help you?

2 Likes

Okay, right yes, and firstly thanks a mill for your advice. So I entered the code, and usually it gives the “errors” feedback. I uploaded a screenshot

what’s your code supposed to do?

you have not said that. can’t debug without knowing what should happen and what is happening instead