Last active
June 22, 2017 20:51
-
-
Save jacobq/a716e4104aa3bf975df2285eb44831c9 to your computer and use it in GitHub Desktop.
Array.any Example
This file contains hidden or 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', | |
| testArrayAny: Ember.computed(function() { | |
| let emptyArray = Ember.A(); | |
| let singleValuedArray = Ember.A([true]); | |
| let specialArray = Ember.A([null, undefined, NaN]); | |
| let normalArray = Ember.A([0,1,2,3]); | |
| let cases = [{ | |
| name: 'true if even; false otherwise', | |
| f: x => x % 2 === 0 | |
| }, { | |
| name: '1 if even; 0 otherwise', | |
| f: x => x % 2 === 0 | |
| }, { | |
| name: 'true if odd; false otherwise', | |
| f: x => x % 2 === 1 | |
| }, { | |
| name: '1 if odd; 0 otherwise', | |
| f: x => (x % 2 === 1) ? 1 : 0 | |
| }, { | |
| name: 'Always true', | |
| f: x => true | |
| }, { | |
| name: 'Always false', | |
| f: x => false | |
| }, { | |
| name: 'Always null (falsey)', | |
| f: x => null | |
| }, { | |
| name: 'Always 0 (falsey)', | |
| f: x => 0 | |
| }, { | |
| name: 'Always 1 (truthy)', | |
| f: x => 1 | |
| }, { | |
| name: 'Identity', | |
| f: x => x | |
| }]; | |
| return cases.map(({name, f}) => { | |
| return { | |
| name: name, | |
| empty: emptyArray.any(f), | |
| single: singleValuedArray.any(f), | |
| special: specialArray.any(f), | |
| normal: normalArray.any(f) | |
| }; | |
| }); | |
| }) | |
| }); |
This file contains hidden or 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
| body { | |
| margin: 12px 16px; | |
| font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
| font-size: 12pt; | |
| } | |
| table { | |
| width: 100%; | |
| } | |
| th { | |
| text-align: left; | |
| } |
This file contains hidden or 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.12.1", | |
| "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.12.0", | |
| "ember-template-compiler": "2.12.0", | |
| "ember-testing": "2.12.0" | |
| }, | |
| "addons": { | |
| "ember-data": "2.12.1" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment