+ 2
What ways can you suggest for making group of if...else statements shorter?
I know switch, but it seems as long as if..else.
3 Antworten
+ 1
Hi. You can use a short form of the if...else statement
result = condition ? conditionTrue() : conditionFalse();
Also this statements can be nested into each other but this can lead to the complex statement that is hard to read and maintain.
Here is the sample code:
function writeChar(c) {
document.write(c+'<br>');
}
(1 < 2) ? writeChar('Y') : writeChar('N'); // writes 'Y'
0
use switch statement... or one of the thing i learnt in my senior secondary class... create recursive functions to check... but this works only in specific cases.
0
Use map(object) data structure. For key put condition, and value should be corresponding function. To access function for processing data , get function from map by condition (key or property) and call