Skip to content

Instantly share code, notes, and snippets.

@ASH-Bryan
Last active January 31, 2018 21:00
Show Gist options
  • Save ASH-Bryan/21c6f22c21b5ac8d23a51c18d30aaa0e to your computer and use it in GitHub Desktop.
Save ASH-Bryan/21c6f22c21b5ac8d23a51c18d30aaa0e to your computer and use it in GitHub Desktop.
Unique Array
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
simpleYears: Ember.computed('newsletters', function() {
const years = [2015, 2015, 2015]
console.log(years)
return years
.map(item => item)
.uniq()
}),
years: Ember.computed('newsletters', function() {
return this.get('newsletters')
.map(item => item.Year)
.uniq()
}),
newsletters: [
{
"id": 0,
"Year": 2016,
"ImageSource": "/files/M965-115A-Q3%20AF%20Newsletter_Quarter_3_450%20X%20582_tcm39-118170.jpg",
"Link": "/files/M965-115A-Q3%20AF%20Newsletter_Quarter_3_tcm39-118171.pdf",
"Summary": "This edition of the Active&Fit® newsletter illustrates how “intrinsic motivators” can help you meet your goals, details why rowing ranks as one of the best exercises, offers tips to cope with workout burnout, and goes over new cholesterol guidelines.",
"Title": "Active&Fit Newsletter Volume 7, Issue 3"
},
{
"id": 0,
"Year": 2016,
"ImageSource": "/files/M965-115A-Q3%20AF%20Newsletter_Quarter_3_450%20X%20582_tcm39-118170.jpg",
"Link": "/files/M965-115A-Q3%20AF%20Newsletter_Quarter_3_tcm39-118171.pdf",
"Summary": "This edition of the Active&Fit® newsletter illustrates how “intrinsic motivators” can help you meet your goals, details why rowing ranks as one of the best exercises, offers tips to cope with workout burnout, and goes over new cholesterol guidelines.",
"Title": "Active&Fit Newsletter Volume 7, Issue 3"
},
{
"id": 0,
"Year": 2016,
"ImageSource": "/files/M965-115A-Q3%20AF%20Newsletter_Quarter_3_450%20X%20582_tcm39-118170.jpg",
"Link": "/files/M965-115A-Q3%20AF%20Newsletter_Quarter_3_tcm39-118171.pdf",
"Summary": "This edition of the Active&Fit® newsletter illustrates how “intrinsic motivators” can help you meet your goals, details why rowing ranks as one of the best exercises, offers tips to cope with workout burnout, and goes over new cholesterol guidelines.",
"Title": "Active&Fit Newsletter Volume 7, Issue 3"
}
]
});
<h1>Unique arrays</h1>
<br>
<h3>Simple Years</h3>
{{#each simpleYears as |year|}}
{{year}}
{{/each}}
<h3>Property Years</h3>
{{#each years as |year|}}
{{year}}
{{/each}}
<br>
{
"version": "0.13.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment