There are some issues with the code, just some comments from me.
(1)
These two statements don’t make sense, as the condition always is false (and the break, never gets executed). So, what is the purpose of these in your code?
if (array >= limit) { break; }
if (matches >= limit) { break; }
(2)
Here is another statement. What is the code doing within the if-else statement? If you write some comments within the code, it will be easier to debug and find what the issue is.
You can also try to place some console.log statements and observe the variable values.
if (from === undefined || to === undefined) {
// .... your code,
// this is when the parameters "from" or "to" are not specified, and when
// "from" and "to" do not have values
} else {
// .... your code
// this is when both "from" and "to" have values
}
Well i tried so much and i dont understand what to do with it then i took that function from some repo its working but not passing the last case and also count test case
have a look and tell me where it is wrong.