+ 1

Why doesn't the TERNARY give the same results as the IF? They seem equivalent!

a===b ? 0: a<b ? -1: 1; // TERNARY if(a<b){ return -1; } else if(b<a){ return 1; } return 0; // IF STATEMENTS Ternary does nothing to the array....... The if returns the ascending order..... https://code.sololearn.com/WBck0w23H5bv/?ref=app

28th Jun 2020, 9:13 AM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar
9 Respostas
+ 3
you're missing return. return a===b ? 0: a<b ? -1: 1;
28th Jun 2020, 9:28 AM
Taste
Taste - avatar
+ 2
asɥɐ🔹ʞɐɹnnƃı🇺🇬 , please show the whole code linked to Playground, otherwise it is hard to guess the problem only seeing just a fraction of the whole.
28th Jun 2020, 9:18 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
Yep! They are! Ćheyat
28th Jun 2020, 2:03 PM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar
+ 1
😂😅😅😅 Thanks TheWh¡teCat 🇧🇬 Taste I feel so stupid🙆🙆🙈🙈😂
28th Jun 2020, 9:34 AM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar
+ 1
asɥɐ🔹ʞɐɹnnƃı🇺🇬 , the "thanks" should go to Taste . He found it before me 🐱
28th Jun 2020, 9:39 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
yes, its just one liner if else
28th Jun 2020, 9:19 AM
Taste
Taste - avatar
28th Jun 2020, 9:26 AM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar
0
Taste , exactly 🐱
28th Jun 2020, 9:29 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Ummm.. Because they are..😆😆
28th Jun 2020, 12:13 PM
Saphal Poudyal
Saphal Poudyal - avatar