Created
April 19, 2016 19:37
-
-
Save iirving/c45915d3df1c0d8b71b557c14a37a5f4 to your computer and use it in GitHub Desktop.
save with Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
})); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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