What does ' ? ' and ' : ' mean in this batch of code for filtering and sorting? [duplicate]Question mark and colon in JavaScriptMVC 3 LINQ Custom Sorting and Filtering with User-Specified Fields (Properties)How to sort distance in sectional table view?why my newly created table is sorted based on the first column?How can I sort the list in my view (IEnumerable) and keep my filtering in place?angular 2 sort and filterAngular - What is the meanings of module.id in component?Sorting of JCombo Box's Not working while sorting Jtable ColumnWhat does Angular 2 hashtags in template mean?vba sort and filter using range objectswhat does $ mean in Angular 7

What are the cons of stateless password generators?

Are all French verb conjugation tenses and moods practical and efficient?

May a hotel provide accommodation for fewer people than booked?

Should students have access to past exams or an exam bank?

Do the books ever say oliphaunts aren’t elephants?

Exploiting the delay when a festival ticket is scanned

Antonym of "Megalomania"

When does the Homunculus die, exactly?

Is it possible to tell if a child will turn into a Hag?

Embedded C - Most elegant way to insert a delay

Bouncing map back into its bounds, after user dragged it out

Is Ear Protection Necessary For General Aviation Airplanes?

How does Asimov's second law deal with contradictory orders from different people?

Solve equation using Mathematica

Was the Psych theme song written for the show?

My employer is refusing to give me the pay that was advertised after an internal job move

What does "in official capacity" mean?

Efficiently finding furthest two nodes in a graph

Little Lost Robot

What is this kind of symbol meant to be?

Raindrops in Python

Was Donald Trump at ground zero helping out on 9-11?

How should I quote American English speakers in a British English essay?

How can I convert a linear narrative into a branching narrative?



What does ' ? ' and ' : ' mean in this batch of code for filtering and sorting? [duplicate]


Question mark and colon in JavaScriptMVC 3 LINQ Custom Sorting and Filtering with User-Specified Fields (Properties)How to sort distance in sectional table view?why my newly created table is sorted based on the first column?How can I sort the list in my view (IEnumerable) and keep my filtering in place?angular 2 sort and filterAngular - What is the meanings of module.id in component?Sorting of JCombo Box's Not working while sorting Jtable ColumnWhat does Angular 2 hashtags in template mean?vba sort and filter using range objectswhat does $ mean in Angular 7






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1
















This question already has an answer here:



  • Question mark and colon in JavaScript

    7 answers



I read about ternary operators but both the filter data and sort data is still kind of confusing. I might be understanding it wrong but it seems to be a sort of IF.



This is from the ZORRO framework. Section - Filter and Sorter



https://ng.ant.design/components/table/en#components-table-demo-virtual



search(): void 
/** filter data **/
const filterFunc = (item: name: string; age: number; address: string ) =>
(this.searchAddress ? item.address.indexOf(this.searchAddress) !== -1 : true) &&
(this.listOfSearchName.length ? this.listOfSearchName.some(name => item.name.indexOf(name) !== -1) : true);
const data = this.listOfData.filter(item => filterFunc(item));
console.log(data);
/** sort data **/
if (this.sortName && this.sortValue)
this.listOfDisplayData = data.sort((a, b) =>
this.sortValue === 'ascend'
? a[this.sortName!] > b[this.sortName!]
? 1
: -1
: b[this.sortName!] > a[this.sortName!]
? 1
: -1
);
else
this.listOfDisplayData = data;












share|improve this question
















marked as duplicate by jmoerdyk, Amy, Jota.Toledo, R. Richards, jcalz typescript
Users with the  typescript badge can single-handedly close typescript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 14:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    The code contains a chained conditional (or ternary) operator

    – jmoerdyk
    Mar 26 at 21:28

















-1
















This question already has an answer here:



  • Question mark and colon in JavaScript

    7 answers



I read about ternary operators but both the filter data and sort data is still kind of confusing. I might be understanding it wrong but it seems to be a sort of IF.



This is from the ZORRO framework. Section - Filter and Sorter



https://ng.ant.design/components/table/en#components-table-demo-virtual



search(): void 
/** filter data **/
const filterFunc = (item: name: string; age: number; address: string ) =>
(this.searchAddress ? item.address.indexOf(this.searchAddress) !== -1 : true) &&
(this.listOfSearchName.length ? this.listOfSearchName.some(name => item.name.indexOf(name) !== -1) : true);
const data = this.listOfData.filter(item => filterFunc(item));
console.log(data);
/** sort data **/
if (this.sortName && this.sortValue)
this.listOfDisplayData = data.sort((a, b) =>
this.sortValue === 'ascend'
? a[this.sortName!] > b[this.sortName!]
? 1
: -1
: b[this.sortName!] > a[this.sortName!]
? 1
: -1
);
else
this.listOfDisplayData = data;












share|improve this question
















marked as duplicate by jmoerdyk, Amy, Jota.Toledo, R. Richards, jcalz typescript
Users with the  typescript badge can single-handedly close typescript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 14:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    The code contains a chained conditional (or ternary) operator

    – jmoerdyk
    Mar 26 at 21:28













-1












-1








-1









This question already has an answer here:



  • Question mark and colon in JavaScript

    7 answers



I read about ternary operators but both the filter data and sort data is still kind of confusing. I might be understanding it wrong but it seems to be a sort of IF.



This is from the ZORRO framework. Section - Filter and Sorter



https://ng.ant.design/components/table/en#components-table-demo-virtual



search(): void 
/** filter data **/
const filterFunc = (item: name: string; age: number; address: string ) =>
(this.searchAddress ? item.address.indexOf(this.searchAddress) !== -1 : true) &&
(this.listOfSearchName.length ? this.listOfSearchName.some(name => item.name.indexOf(name) !== -1) : true);
const data = this.listOfData.filter(item => filterFunc(item));
console.log(data);
/** sort data **/
if (this.sortName && this.sortValue)
this.listOfDisplayData = data.sort((a, b) =>
this.sortValue === 'ascend'
? a[this.sortName!] > b[this.sortName!]
? 1
: -1
: b[this.sortName!] > a[this.sortName!]
? 1
: -1
);
else
this.listOfDisplayData = data;












share|improve this question

















This question already has an answer here:



  • Question mark and colon in JavaScript

    7 answers



I read about ternary operators but both the filter data and sort data is still kind of confusing. I might be understanding it wrong but it seems to be a sort of IF.



This is from the ZORRO framework. Section - Filter and Sorter



https://ng.ant.design/components/table/en#components-table-demo-virtual



search(): void 
/** filter data **/
const filterFunc = (item: name: string; age: number; address: string ) =>
(this.searchAddress ? item.address.indexOf(this.searchAddress) !== -1 : true) &&
(this.listOfSearchName.length ? this.listOfSearchName.some(name => item.name.indexOf(name) !== -1) : true);
const data = this.listOfData.filter(item => filterFunc(item));
console.log(data);
/** sort data **/
if (this.sortName && this.sortValue)
this.listOfDisplayData = data.sort((a, b) =>
this.sortValue === 'ascend'
? a[this.sortName!] > b[this.sortName!]
? 1
: -1
: b[this.sortName!] > a[this.sortName!]
? 1
: -1
);
else
this.listOfDisplayData = data;







This question already has an answer here:



  • Question mark and colon in JavaScript

    7 answers







angular typescript sorting angular7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 0:11









Matt Tester

2,8442 gold badges24 silver badges30 bronze badges




2,8442 gold badges24 silver badges30 bronze badges










asked Mar 26 at 21:23









Rod FloresRod Flores

153 bronze badges




153 bronze badges





marked as duplicate by jmoerdyk, Amy, Jota.Toledo, R. Richards, jcalz typescript
Users with the  typescript badge can single-handedly close typescript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 14:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











marked as duplicate by jmoerdyk, Amy, Jota.Toledo, R. Richards, jcalz typescript
Users with the  typescript badge can single-handedly close typescript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 14:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by jmoerdyk, Amy, Jota.Toledo, R. Richards, jcalz typescript
Users with the  typescript badge can single-handedly close typescript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 14:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1





    The code contains a chained conditional (or ternary) operator

    – jmoerdyk
    Mar 26 at 21:28












  • 1





    The code contains a chained conditional (or ternary) operator

    – jmoerdyk
    Mar 26 at 21:28







1




1





The code contains a chained conditional (or ternary) operator

– jmoerdyk
Mar 26 at 21:28





The code contains a chained conditional (or ternary) operator

– jmoerdyk
Mar 26 at 21:28












2 Answers
2






active

oldest

votes


















2














It is confusing looking code (and so not recommended), but it is a series of ternary operators. This is exactly the same as an if/else statement, just written in a short-hand way.



So it looks confusing because the if (the ?) and else (the :) of the first ternary operator is itself another ternary operator!



 return this.sortValue === 'ascend'
? a[this.sortName!] > b[this.sortName!]
? 1
: -1
: b[this.sortName!] > a[this.sortName!]
? 1
: -1


Is the same as:



if (this.sortValue === 'ascend') 
if(a[this.sortName!] > b[this.sortName!])
return 1;
else
return -1;

else
if (b[this.sortName!] > a[this.sortName!])
return 1;
else
return -1;







share|improve this answer



























  • this is super helpful in the way you translated it to regular statements. Thank you

    – Rod Flores
    Mar 27 at 13:48


















0














It is known as Conditional Operator (also called ternary operator).



It has the form of: condition ? value-if-true : value-if-false
Think of the ? as "then" and : as "else".



For example,



return this.sortValue === 'ascend'
? ( a[this.sortName!] > b[this.sortName!] ? 1 : -1 )
: (b[this.sortName!] > a[this.sortName!] ? 1 : -1)





share|improve this answer

































    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    It is confusing looking code (and so not recommended), but it is a series of ternary operators. This is exactly the same as an if/else statement, just written in a short-hand way.



    So it looks confusing because the if (the ?) and else (the :) of the first ternary operator is itself another ternary operator!



     return this.sortValue === 'ascend'
    ? a[this.sortName!] > b[this.sortName!]
    ? 1
    : -1
    : b[this.sortName!] > a[this.sortName!]
    ? 1
    : -1


    Is the same as:



    if (this.sortValue === 'ascend') 
    if(a[this.sortName!] > b[this.sortName!])
    return 1;
    else
    return -1;

    else
    if (b[this.sortName!] > a[this.sortName!])
    return 1;
    else
    return -1;







    share|improve this answer



























    • this is super helpful in the way you translated it to regular statements. Thank you

      – Rod Flores
      Mar 27 at 13:48















    2














    It is confusing looking code (and so not recommended), but it is a series of ternary operators. This is exactly the same as an if/else statement, just written in a short-hand way.



    So it looks confusing because the if (the ?) and else (the :) of the first ternary operator is itself another ternary operator!



     return this.sortValue === 'ascend'
    ? a[this.sortName!] > b[this.sortName!]
    ? 1
    : -1
    : b[this.sortName!] > a[this.sortName!]
    ? 1
    : -1


    Is the same as:



    if (this.sortValue === 'ascend') 
    if(a[this.sortName!] > b[this.sortName!])
    return 1;
    else
    return -1;

    else
    if (b[this.sortName!] > a[this.sortName!])
    return 1;
    else
    return -1;







    share|improve this answer



























    • this is super helpful in the way you translated it to regular statements. Thank you

      – Rod Flores
      Mar 27 at 13:48













    2












    2








    2







    It is confusing looking code (and so not recommended), but it is a series of ternary operators. This is exactly the same as an if/else statement, just written in a short-hand way.



    So it looks confusing because the if (the ?) and else (the :) of the first ternary operator is itself another ternary operator!



     return this.sortValue === 'ascend'
    ? a[this.sortName!] > b[this.sortName!]
    ? 1
    : -1
    : b[this.sortName!] > a[this.sortName!]
    ? 1
    : -1


    Is the same as:



    if (this.sortValue === 'ascend') 
    if(a[this.sortName!] > b[this.sortName!])
    return 1;
    else
    return -1;

    else
    if (b[this.sortName!] > a[this.sortName!])
    return 1;
    else
    return -1;







    share|improve this answer















    It is confusing looking code (and so not recommended), but it is a series of ternary operators. This is exactly the same as an if/else statement, just written in a short-hand way.



    So it looks confusing because the if (the ?) and else (the :) of the first ternary operator is itself another ternary operator!



     return this.sortValue === 'ascend'
    ? a[this.sortName!] > b[this.sortName!]
    ? 1
    : -1
    : b[this.sortName!] > a[this.sortName!]
    ? 1
    : -1


    Is the same as:



    if (this.sortValue === 'ascend') 
    if(a[this.sortName!] > b[this.sortName!])
    return 1;
    else
    return -1;

    else
    if (b[this.sortName!] > a[this.sortName!])
    return 1;
    else
    return -1;








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 26 at 21:47

























    answered Mar 26 at 21:42









    Matt TesterMatt Tester

    2,8442 gold badges24 silver badges30 bronze badges




    2,8442 gold badges24 silver badges30 bronze badges















    • this is super helpful in the way you translated it to regular statements. Thank you

      – Rod Flores
      Mar 27 at 13:48

















    • this is super helpful in the way you translated it to regular statements. Thank you

      – Rod Flores
      Mar 27 at 13:48
















    this is super helpful in the way you translated it to regular statements. Thank you

    – Rod Flores
    Mar 27 at 13:48





    this is super helpful in the way you translated it to regular statements. Thank you

    – Rod Flores
    Mar 27 at 13:48













    0














    It is known as Conditional Operator (also called ternary operator).



    It has the form of: condition ? value-if-true : value-if-false
    Think of the ? as "then" and : as "else".



    For example,



    return this.sortValue === 'ascend'
    ? ( a[this.sortName!] > b[this.sortName!] ? 1 : -1 )
    : (b[this.sortName!] > a[this.sortName!] ? 1 : -1)





    share|improve this answer





























      0














      It is known as Conditional Operator (also called ternary operator).



      It has the form of: condition ? value-if-true : value-if-false
      Think of the ? as "then" and : as "else".



      For example,



      return this.sortValue === 'ascend'
      ? ( a[this.sortName!] > b[this.sortName!] ? 1 : -1 )
      : (b[this.sortName!] > a[this.sortName!] ? 1 : -1)





      share|improve this answer



























        0












        0








        0







        It is known as Conditional Operator (also called ternary operator).



        It has the form of: condition ? value-if-true : value-if-false
        Think of the ? as "then" and : as "else".



        For example,



        return this.sortValue === 'ascend'
        ? ( a[this.sortName!] > b[this.sortName!] ? 1 : -1 )
        : (b[this.sortName!] > a[this.sortName!] ? 1 : -1)





        share|improve this answer













        It is known as Conditional Operator (also called ternary operator).



        It has the form of: condition ? value-if-true : value-if-false
        Think of the ? as "then" and : as "else".



        For example,



        return this.sortValue === 'ascend'
        ? ( a[this.sortName!] > b[this.sortName!] ? 1 : -1 )
        : (b[this.sortName!] > a[this.sortName!] ? 1 : -1)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 3:32









        Seba CherianSeba Cherian

        8791 silver badge14 bronze badges




        8791 silver badge14 bronze badges
















            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현