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
| expect(spyTrigger.call).toEqual(1); |
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
| var spyTrigger = spyOn(Events, "trigger"); |
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
| var mockObject = spyOn(object, Constructor).andCallFake(function () { | |
| return { | |
| method1: function () {}, | |
| method2: function () {} | |
| }; | |
| }); |
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
| var a = function () { | |
| return a(); | |
| var a = function () { | |
| return 1; | |
| }; | |
| function a() { | |
| return 2; | |
| } |
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
| var a = 1, | |
| fn = function () { | |
| alert(a); | |
| var a = 10; | |
| }; | |
| // a is undefined when alerted! |
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
| var arr = [ | |
| {details: {name: {first: 'Joseph', last: 'Chapman'}}}, | |
| {details: {name: {first: 'Andrew', last: 'Chapman'}}}, | |
| {details: {name: {first: '234', last: '111'}}}, | |
| {details: {name: {first: 'Joseph', last: 'Hinge'}}}, | |
| {details: {name: {first: 'Simon', last: 'Andrews'}}}, | |
| {details: {name: {first: 'Robert', last: 'Hinge'}}} | |
| ]; | |
| var sortBy = function (key, minor) { |
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
| var arr = [ | |
| {first: 'Joseph', last: 'Chapman'}, | |
| {first: 'Andrew', last: 'Chapman'}, | |
| {first: '234', last: '111'}, | |
| {first: 'Joseph', last: 'Hinge'}, | |
| {first: 'Simon', last: 'Andrews'}, | |
| {first: 'Robert', last: 'Hinge'} | |
| ]; | |
| var sortBy = function (key, minor) { |
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
| var arr = [ | |
| {first: 'Joseph', last: 'Smith'}, | |
| {first: 'Joseph', last: 'Chapman'}, | |
| {first: 'Joseph', last: 'Hinge'} | |
| ]; | |
| var sortBy = function (key) { | |
| return function (o, p) { | |
| var a, b; | |
| if (o && p && typeof o === 'object' && typeof p === 'object') { |
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
| var arr = ['z', 564, 12, 785, 'a', 'dc', 'o', 43, 's', 'r']; | |
| arr.sort(function (a, b) { | |
| if (a === b) { | |
| return 0; | |
| } | |
| if (typeof a === typeof b) { | |
| return a < b ? -1 : 1; | |
| } | |
| return typeof a < typeof b ? -1 : 1; |
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
| var arr = [300, 40, 5]; | |
| arr.sort(function (a, b) { | |
| return a - b; | |
| }); | |
| // Result | |
| 5, 40, 300 |