Did you test your solution? You didn't. If you did, you would be surprised to find out you are missing a return statement.
Don't get me wrong, I'm not scalding you. I'm trying to give you a valuable advice.
Learn to write tests as you learn to write code. It will make you a much better programmer. Trust me.
My bad... "Find and print"... the task is flawed 🤷♂️
Anyway, much better to write console.log(solve(...)) and return a result than print within the working function and retun nothing.
Did you test your solution? You didn't. If you did, you would be surprised to find out you are missing a
return
statement.Don't get me wrong, I'm not scalding you. I'm trying to give you a valuable advice.
Learn to write tests as you learn to write code. It will make you a much better programmer. Trust me.
My bad... "Find and print"... the task is flawed 🤷♂️
Anyway, much better to write
console.log(solve(...))
and return a result than print within the working function and retun nothing.It passed all the test cases provided by HackerRank. And ya thanks for your advice. It'll help me in the future for sure.