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;
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;
angular typescript sorting angular7
marked as duplicate by jmoerdyk, Amy, Jota.Toledo, R. Richards, jcalz
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.
add a comment |
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;
angular typescript sorting angular7
marked as duplicate by jmoerdyk, Amy, Jota.Toledo, R. Richards, jcalz
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
add a comment |
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;
angular typescript sorting angular7
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
angular typescript sorting angular7
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
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
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
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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;
this is super helpful in the way you translated it to regular statements. Thank you
– Rod Flores
Mar 27 at 13:48
add a comment |
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)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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;
this is super helpful in the way you translated it to regular statements. Thank you
– Rod Flores
Mar 27 at 13:48
add a comment |
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;
this is super helpful in the way you translated it to regular statements. Thank you
– Rod Flores
Mar 27 at 13:48
add a comment |
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;
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;
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
add a comment |
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
add a comment |
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)
add a comment |
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)
add a comment |
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)
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)
answered Mar 27 at 3:32
Seba CherianSeba Cherian
8791 silver badge14 bronze badges
8791 silver badge14 bronze badges
add a comment |
add a comment |
1
The code contains a chained conditional (or ternary) operator
– jmoerdyk
Mar 26 at 21:28