Codewars - need help

Hi, it seems like I am close to finishing this kata: https://www.codewars.com/kata/56af1a20509ce5b9b000001e/train/javascript
but it’s just one part that I’m failing. The beginning of the returned string is supposed to show up as:

OH 43071: 

not

OH 43071:/

It must be my for loop that is wrong? I’ve been trying to figure it out for ages but can’t work it out. Sorry about the regex overload too, there is probably a better way to shorten it.

My code below:

function travel(r, zipcode) {
  let arr = r.split(",");
  let correctZipcode = arr.filter((address) => address.includes(zipcode)).join();
  let streetWithNumber = correctZipcode.replace(/[A-Z]{2,3}|\d{5}/g,"");
  let streetWithNumber2 = streetWithNumber.replace(/\s{2,}/g,"");
  let extractedStreet = streetWithNumber2.match(/[A-Za-z\.]{3,}|,/g).join();
  let streetString = extractedStreet.replace(/.(?=[A-Z])/g," ");
  let streetString2 = streetString.replace(/,(?= )/g,"");
  let extractedNumber = streetWithNumber2.match(/\d{1,4}/g);
  
  let extractedZipcodes = r.match(/[A-Z]{2,3}|\d{5}/g).join().replace(/,/g, " ");
  let newArr = extractedZipcodes.split(/(?= [A-Z])/g);
  let firstPart;
  for(let i = 0; i < newArr.length; i++){
    if(newArr[i] == zipcode) {
       firstPart = zipcode + ":";
    }
    firstPart = zipcode + ":/";
  }
  return firstPart + streetString2 + "/" + extractedNumber;
}

The error comes up as:

Expected: ‘AA 45522:Paris St. Abbeville,Paris St. Abbeville/67,670’, instead got: ‘AA 45522:/Paris St. Abbeville, Paris St. Abbeville/67,670’

Expected: ‘EX 34342:Pussy Cat Rd. Chicago,Pussy Cat Rd. Chicago/10,100’, instead got: ‘EX 34342:/Pussy Cat Rd. Chicago, Pussy Cat Rd. Chicago/10,100’

Expected: ‘EX 34345:Pussy Cat Rd. Chicago/100’, instead got: ‘EX 34345:/Pussy Cat Rd. Chicago/100’

etc

Many thanks

the only place I see in which you are adding :/ is this, maybe you can investigate there?

Yes I wrote that because in the rules it states: ‘If a given zipcode doesn’t exist in the list of clients’ addresses return "zipcode:/"
But since the zipcodes are in the client addresses, the returned string should say “zipcode:” without the forward slash

where is the code that checks if the zipcode exist in the list of clients’ addresses?

It’s supposed to be this part:

let firstPart;
  for(let i = 0; i < newArr.length; i++){
    if(newArr[i] == zipcode) {
       firstPart = zipcode + ":";
    }
    firstPart = zipcode + ":/";
  }

I also tried it with includes() instead of == but that didn’t work either

Hello~!

Looking at this loop, your firstPart = zipcode + ":/" will always run.