-2

I am currently doing an exercise that I got from my school. It's about regex but I am not sure if there is something wrong with my function or my regex code. We were told to use regex101.com to try things out.

in that site it looks like this and it all seems to work.

code in regex101

But in my file I get this. my own code

Here is the code:

function isCheck(words) {
  const check = /\Bche(ck|que)/;
  return check.test('check', 'cheque');
}

So I am thinking that maybe there is something wrong in my function but I am not sure what that could be.

this is what its testing against

describe('The check-checker', () => {
  it.only('should match check', () => {
    const check = 'check';
    assert.equal(matcher.isCheck(check), true);
  });

  it.only('should match cheque', () => {
    const cheque = 'cheque';
    assert.equal(matcher.isCheck(cheque), true);
  });

Does anyone have any ideas?

Julius
  • 21
  • 5
  • @jabaa ah sorry, I added the code now. Do you have any idea what I am missing? – Julius Sep 18 '22 at 04:08
  • Just curious, do we have no input string to function? Cause this function returns results of your test of 'check' and 'cheque' and does nothing to any input string? – risky last Sep 18 '22 at 04:29
  • @riskylast I added what it looks for above. It looked a bit weird in this comment section. – Julius Sep 18 '22 at 05:58
  • Have you tried check.test(words) in the isCheck function? Cause you're taking words as input in function and not using it anywhere – risky last Sep 18 '22 at 11:37
  • @riskylast dude, you are absolutely right! That was the problem. I posted the answer below. Thanks for the help man, really appreciate it. – Julius Sep 18 '22 at 17:54

1 Answers1

0

I finally found it, for anyone else in a similar situation. The function was wrong. I needed a parameter and to call on it in the function.

function isCheck(test) {
  const check2 = /\b(check|cheque)\b/i;
  if (check2.test(test)) {
    return true;
  }
  return false;
}
module.exports.isCheck = isCheck;

There is the code.

Julius
  • 21
  • 5