numsLen>=1&& is unneccessary
and at that point, you can just
return first==last;
or, using numsLen>=1&& you can make the if(numsLen==0){ unnecessary
0
There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.
instead of doing in 2 steps like checking and then returning we are doing in one step in return itself comparing so that i will automatically give true false in return statement right?
please advise
instead of doing in 2 steps like checking and then returning we are doing in one step in return itself comparing so that i will automatically give true false in return statement right?
Yes that's right. We're replacing 3 lines of code with 1 - which is good because it's simpler. And we're also removing a conditional (the "if" test) so the code always executes the same lines of code - which is also good.
Rather than:
if (first == last) {
// Sometimes we run code in here
return true ;
}
// Sometimes we run code here
return false ;
We have now:
// Always run this code
return (first == last) ;
It's best to avoid branches and conditional statements in your code where possible. It makes bugs less likely.
When runing this piece of code, your computer will evaluate the expression first == last.
The value of an expression is a boolean. That's a variable that can hold the value 'true' or 'false'.
When the result/value of that expression is true, it will return true.
When the result/value of that expression is false, it will return false.
So, in fact, it can just return the result/value of that expression.
You write that as:
There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.
Introduction
This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.