Skip to content

Instantly share code, notes, and snippets.

@iirving
Created April 19, 2016 19:37
Show Gist options
  • Save iirving/c45915d3df1c0d8b71b557c14a37a5f4 to your computer and use it in GitHub Desktop.
Save iirving/c45915d3df1c0d8b71b557c14a37a5f4 to your computer and use it in GitHub Desktop.
save with Arrays
import Ember from 'ember';
const students = ['Erick', 'Jim', 'Ducky', 'Lee'];
students.forEach(function(item, index) {
console.log(`student #${index+1} : ${item} `);
});
//upper
const upperCaseStudent = students.map(function(item) {
return item.toUpperCase();
});
upperCaseStudent.forEach(function(item, index) {
console.log(`student #${index+1} : ${item} `);
});
const student = Ember.Object.extend({
name: 'Erik Hanchett'
});
const teacher = Ember.Object.extend({
name: 'John P. Smith'
});
const t= teacher.create();
const s = student.create();
const people = [s,t];
console.log(people.mapBy('name'));
//last, first , push
console.log(students.get('lastObject'));
console.log(students.get('firstObject'));
students.pushObject('Jeff');
console.log(students.get('lastObject'));
//array filters
const array = [1,2,3,5,8,12,20,32];
const newArray = array.filter(function (item, index, self) {
return item > 10;
});
console.log(newArray);
const studentNew = Ember.Object.extend({
grade: null,
name: null
});
// filterBy
const listOfStudents = [
studentNew.create({grade: 'senior', name: 'Jen'}),
studentNew.create({grade: 'freshman', name: 'Ben'}),
studentNew.create({grade: 'senior', name: 'Anna'})
];
const listOfSenior =
listOfStudents.filterBy('grade','senior');
listOfSenior.forEach(function (item, index) {
console.log(item.get('name'));
});
//find
const newItemArray = array.find(function (item, index) {
return item > 10;
});
console.log(newItemArray);
//findBy
const newStudent = listOfStudents.findBy('grade','senior');
console.log(newStudent.get('name'));
// test with every
const arrayOfBig = [11,25,23,30];
console.log(arrayOfBig.every(function(item, index, self) {
return item > 10
})); //true
console.log(arrayOfBig.every(function(item, index, self) {
return item > 20
})); //false
// test with any
console.log(arrayOfBig.any(function(item, idex, self) {
return item > 20;
})); //true
console.log(arrayOfBig.any(function(item, idex, self) {
return item > 40; // false
}));
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.7.2",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment