UNPKG

@moomfe/zenjs

Version:

ZenJS 是一个高性能的 JavaScript 工具库。

934 lines (864 loc) 223 kB
describes.push({ name: 'Array.prototype', describe: [ { name: '$add', describe: [ { name: 'Always return to itself', it: function(){ var arr = []; arr.$add().should.equals( arr ); arr.$add( -1 ).should.equals( arr ); arr.$add( 0 ).should.equals( arr ); arr.$add( 1 ).should.equals( arr ); } }, { name: 'Add to an empty array', it: function(){ Object.$equals( [].$add( -2, 1, 2, 3, 4, 5 ), [ 1, 2, 3, 4, 5 ] ).should.true; Object.$equals( [].$add( -1, 1, 2, 3, 4, 5 ), [ 1, 2, 3, 4, 5 ] ).should.true; Object.$equals( [].$add( 0, 1, 2, 3, 4, 5 ), [ 1, 2, 3, 4, 5 ] ).should.true; Object.$equals( [].$add( 1, 1, 2, 3, 4, 5 ), [ 1, 2, 3, 4, 5 ] ).should.true; Object.$equals( [].$add( 2, 1, 2, 3, 4, 5 ), [ 1, 2, 3, 4, 5 ] ).should.true; } }, { name: 'Add to a non-empty array', it: function(){ Object.$equals( [ 1, 2, 3 ].$add( -5, 4, 5, 6 ), [ 4, 5, 6, 1, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$add( -4, 4, 5, 6 ), [ 4, 5, 6, 1, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$add( -3, 4, 5, 6 ), [ 1, 4, 5, 6, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$add( -2, 4, 5, 6 ), [ 1, 2, 4, 5, 6, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$add( -1, 4, 5, 6 ), [ 1, 2, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$add( 0, 4, 5, 6 ), [ 4, 5, 6, 1, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$add( 1, 4, 5, 6 ), [ 1, 4, 5, 6, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$add( 2, 4, 5, 6 ), [ 1, 2, 4, 5, 6, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$add( 3, 4, 5, 6 ), [ 1, 2, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$add( 4, 4, 5, 6 ), [ 1, 2, 3, 4, 5, 6 ] ).should.true; } } ] }, { name: '$concat', describe: [ { name: 'Always return to itself', it: function(){ var arr = []; arr.$concat().should.equals( arr ); arr.$concat( 1 ).should.equals( arr ); arr.$concat( [] ).should.equals( arr ); arr.$concat( [ 1, 2, 3 ] ).should.equals( arr ); } }, { name: 'Normal use', it: function(){ Object.$equals( [].$concat( 4 ), [ 4 ] ).should.true; Object.$equals( [ 1 ].$concat( 4, 5 ), [ 1, 4, 5 ] ).should.true; Object.$equals( [ 1, 2 ].$concat( 4, 5, 6 ), [ 1, 2, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concat( 4, 5, 6, 7 ), [ 1, 2, 3, 4, 5, 6, 7 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concat( 4, [ 5, 6 ], 7, 8 ), [ 1, 2, 3, 4, 5, 6, 7, 8 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concat( 4, [ 5, 6 ], [ 7, 8, 9 ] ), [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concat( 4, [ [ 5, 6 ], [ 7, 8, 9 ] ] ), [ 1, 2, 3, 4, [ 5, 6 ], [ 7, 8, 9 ] ] ).should.true; } } ] }, { name: '$concatTo', describe: [ { name: 'Always return to itself', it: function(){ var arr = []; arr.$concatTo().should.equals( arr ); arr.$concatTo( 0 ).should.equals( arr ); arr.$concatTo( 1, [] ).should.equals( arr ); arr.$concatTo( 2, [ 1, 2, 3 ] ).should.equals( arr ); } }, { name: 'Normal use', it: function(){ Object.$equals( [].$concatTo( -2, 1, 2, 3 ), [ 1, 2, 3 ] ).should.true; Object.$equals( [].$concatTo( -1, 1, 2, 3 ), [ 1, 2, 3 ] ).should.true; Object.$equals( [].$concatTo( 0, 1, 2, 3 ), [ 1, 2, 3 ] ).should.true; Object.$equals( [].$concatTo( 1, 1, 2, 3 ), [ 1, 2, 3 ] ).should.true; Object.$equals( [].$concatTo( 2, 1, 2, 3 ), [ 1, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( -5, 4, 5, 6 ), [ 4, 5, 6, 1, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( -4, 4, 5, 6 ), [ 4, 5, 6, 1, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( -3, 4, 5, 6 ), [ 1, 4, 5, 6, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( -2, 4, 5, 6 ), [ 1, 2, 4, 5, 6, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( -1, 4, 5, 6 ), [ 1, 2, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( 0, 4, 5, 6 ), [ 4, 5, 6, 1, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( 1, 4, 5, 6 ), [ 1, 4, 5, 6, 2, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( 2, 4, 5, 6 ), [ 1, 2, 4, 5, 6, 3 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( 3, 4, 5, 6 ), [ 1, 2, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( 4, 4, 5, 6 ), [ 1, 2, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( -1, 4, 5, 6, 7, 8, 9 ), [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( -1, [ 4, 5, 6 ], 7, 8, 9 ), [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( -1, [ 4, 5, 6 ], [ 7, 8, 9 ] ), [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ).should.true; Object.$equals( [ 1, 2, 3 ].$concatTo( -1, [ [ 4, 5, 6 ], [ 7, 8, 9 ] ] ), [ 1, 2, 3, [ 4, 5, 6 ], [ 7, 8, 9 ] ] ).should.true; } } ] }, { name: '$delete / $remove', describe: [ { name: 'Return itself by default', it: function(){ var arr = []; arr.$delete().should.equals( arr ); arr.$delete( 0 ).should.equals( arr ); arr.$delete( 1 ).should.equals( arr ); arr.$delete( 1, 1 ).should.equals( arr ); } }, { name: 'Can return deleted content', it: function(){ Object.$equals( [ 1, 2, 3, 4, 5 ].$delete( 1, 3, true ), [ 2, 3, 4 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5 ].$delete( 0, 99, true ), [ 1, 2, 3, 4, 5 ] ).should.true; } }, { name: 'Normal use', it: function(){ Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( -7 ), [ 2, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( -6 ), [ 2, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( -5 ), [ 1, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( -4 ), [ 1, 2, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( -3 ), [ 1, 2, 3, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( -2 ), [ 1, 2, 3, 4, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( -1 ), [ 1, 2, 3, 4, 5 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( 0 ), [ 2, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( 1 ), [ 1, 3, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( 2 ), [ 1, 2, 4, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( 3 ), [ 1, 2, 3, 5, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( 4 ), [ 1, 2, 3, 4, 6 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( 5 ), [ 1, 2, 3, 4, 5 ] ).should.true; Object.$equals( [ 1, 2, 3, 4, 5, 6 ].$delete( 6 ), [ 1, 2, 3, 4, 5 ] ).should.true; } }, { name: 'Delete the first one when there are no parameters', it: function(){ Object.$equals( [ 1, 2, 3 ].$delete(), [ 2, 3 ] ).should.true; } } ] }, { name: '$deleteValue / $removeValue', describe: [ { name: 'Use congruent to delete', it: function(){ // No parameters Object.$equals( [ 1, 2, 3, 4 ].$deleteValue( 4 ), [ 1, 2, 3 ] ).should.true; Object.$equals( [ 4, 4, 4, 4 ].$deleteValue( 4 ), [] ).should.true; Object.$equals( [ 4, 1, 2, 4 ].$deleteValue( 4 ), [ 1, 2 ] ).should.true; Object.$equals( [ false, 0, '' ].$deleteValue( false ), [ 0, '' ] ).should.true; Object.$equals( [ null, undefined ].$deleteValue( null ), [ undefined ] ).should.true; // Using parameters Object.$equals( [ 1, 2, 3, 4 ].$deleteValue( 4, true ), [ 1, 2, 3 ] ).should.true; Object.$equals( [ 4, 4, 4, 4 ].$deleteValue( 4, true ), [] ).should.true; Object.$equals( [ 4, 1, 2, 4 ].$deleteValue( 4, true ), [ 1, 2 ] ).should.true; Object.$equals( [ false, 0, '' ].$deleteValue( false, true ), [ 0, '' ] ).should.true; Object.$equals( [ null, undefined ].$deleteValue( null, true ), [ undefined ] ).should.true; } }, { name: 'Use double to delete', it: function(){ Object.$equals( [ 1, 2, 3, 4 ].$deleteValue( 4, false ), [ 1, 2, 3 ] ).should.true; Object.$equals( [ 4, 4, 4, 4 ].$deleteValue( 4, false ), [] ).should.true; Object.$equals( [ 4, 1, 2, 4 ].$deleteValue( 4, false ), [ 1, 2 ] ).should.true; Object.$equals( [ false, 0, '' ].$deleteValue( false, false ), [] ).should.true; Object.$equals( [ null, undefined ].$deleteValue( null, false ), [] ).should.true; } }, { name: 'Use a custom method to delete', it: function(){ Object.$equals( [ 1, 2, 3, 4 ].$deleteValue( 4, Object.$equals ), [ 1, 2, 3 ] ).should.true; Object.$equals( [ 4, 4, 4, 4 ].$deleteValue( 4, Object.$equals ), [] ).should.true; Object.$equals( [ 4, 1, 2, 4 ].$deleteValue( 4, Object.$equals ), [ 1, 2 ] ).should.true; var arr = [ { ZenJS: true }, { ZenJS: false }, { ZenUI: true }, { ZenUI: false } ]; // ( 1 Object.$equals( arr.slice().$deleteValue( { ZenJS: true }, Object.$equals ), arr.slice().$delete( 0 ) ).should.true; // ( 2 Object.$equals( arr.slice().$deleteValue( 'ZenJS', function( json, key ){ return key in json; }), arr.slice().$delete( 0, 2 ) ).should.true; // ( 3 Object.$equals( arr.slice().$deleteValue(function( json ){ return 'ZenUI' in json; }), arr.slice().$delete( -2, 2 ) ).should.true } } ] }, { name: '$find', describe: [ { name: 'Traversing the contents of the collection using a custom method', it: function(){ var arr = [ 0, 1, 2, 3, 3 ]; Object.$equals( arr.$find(function( value ){ return value === -4 }), undefined ).should.true; Object.$equals( arr.$find(function( value ){ return value === -3 }), undefined ).should.true; Object.$equals( arr.$find(function( value ){ return value === -2 }), undefined ).should.true; Object.$equals( arr.$find(function( value ){ return value === -1 }), undefined ).should.true; Object.$equals( arr.$find(function( value ){ return value }), 1 ).should.true; Object.$equals( arr.$find(function( value ){ return value === 0 }), 0 ).should.true; Object.$equals( arr.$find(function( value ){ return value === 1 }), 1 ).should.true; Object.$equals( arr.$find(function( value ){ return value === 2 }), 2 ).should.true; Object.$equals( arr.$find(function( value ){ return value === 3 }), 3 ).should.true; Object.$equals( arr.$find(function( value ){ return value === 4 }), undefined ).should.true; var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; arr.$find(function( obj ){ return obj.name }).should.equals( arr[0] ); arr.$find(function( obj ){ return obj.type }).should.equals( arr[3] ); arr.$find(function( obj ){ return obj.name && obj.type }).should.equals( arr[3] ); arr.$find(function( obj ){ return obj.name == 'zenjs' }).should.equals( arr[1] ); arr.$find(function( obj ){ return obj.name == 'zenui' }).should.equals( arr[2] ); arr.$find(function( obj ){ return obj.type == 'js' }).should.equals( arr[3] ); arr.$find(function( obj ){ return obj.type == 'ui' }).should.equals( arr[4] ); } }, { name: 'Incoming object for lookup', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; Object.$equals( arr.$find({ name: 'xxx' }), undefined ).should.true; arr.$find({ name: 'zen' }).should.equals( arr[0] ); arr.$find({ name: 'zenjs' }).should.equals( arr[1] ); arr.$find({ name: 'zenui' }).should.equals( arr[2] ); arr.$find({ type: 'js' }).should.equals( arr[3] ); arr.$find({ type: 'ui' }).should.equals( arr[4] ); arr.$find({ name: 'zenjs', type: 'js' }).should.equals( arr[3] ); arr.$find({ name: 'zenui', type: 'ui' }).should.equals( arr[4] ); } }, { name: 'Pass in an array for lookup', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; Object.$equals( arr.$find([ 'name', 'xxx' ]), undefined ).should.true; arr.$find([ 'name', 'zen' ]).should.equals( arr[0] ); arr.$find([ 'name', 'zenjs' ]).should.equals( arr[1] ); arr.$find([ 'name', 'zenui' ]).should.equals( arr[2] ); arr.$find([ 'type', 'js' ]).should.equals( arr[3] ); arr.$find([ 'type', 'ui' ]).should.equals( arr[4] ); arr.$find([ 'name', 'zenjs', 'type', 'js' ]).should.equals( arr[3] ); arr.$find([ 'name', 'zenui', 'type', 'ui' ]).should.equals( arr[4] ); } }, { name: 'Test the predicate parameter', it: function(){ var arr = [ { arr: false }, { arr: 0 } ]; // Incoming object for lookup arr.$find( { arr: 0 } ).should.equals( arr[1] ); arr.$find( { arr: 0 }, true ).should.equals( arr[1] ); arr.$find( { arr: 0 }, false ).should.equals( arr[0] ); arr.$find( { arr: 0 }, Object.$equals ).should.equals( arr[1] ); // Pass in an array for lookup arr.$find( [ 'arr', 0 ] ).should.equals( arr[1] ); arr.$find( [ 'arr', 0 ], true ).should.equals( arr[1] ); arr.$find( [ 'arr', 0 ], false ).should.equals( arr[0] ); arr.$find( [ 'arr', 0 ], Object.$equals ).should.equals( arr[1] ); } }, { name: 'Test the fromIndex parameter', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; // Traversing the contents of the collection using a custom method arr.$find( function( obj ){ return obj.name }, 1 ).should.equals( arr[1] ); arr.$find( function( obj ){ return obj.name == 'zenjs' }, 2 ).should.equals( arr[3] ); arr.$find( function( obj ){ return obj.name == 'zenui' }, 3 ).should.equals( arr[4] ); // Incoming object for lookup Object.$equals( arr.$find( { name: 'zen' }, 1 ), undefined ).should.true; arr.$find( { name: 'zenjs' }, 2 ).should.equals( arr[3] ); arr.$find( { name: 'zenui' }, 3 ).should.equals( arr[4] ); // Pass in an array for lookup Object.$equals( arr.$find( [ 'name', 'zen' ], 1 ), undefined ).should.true; arr.$find( [ 'name', 'zenjs' ], 2 ).should.equals( arr[3] ); arr.$find( [ 'name', 'zenui' ], 3 ).should.equals( arr[4] ); } }, { name: 'Test the predicate parameter and fromIndex parameter', it: function(){ var arr = [ { arr: false }, { arr: 0 }, { arr: false }, { arr: 0 } ]; // Incoming object for lookup arr.$find( { arr: 0 } ).should.equals( arr[1] ); arr.$find( { arr: 0 }, true ).should.equals( arr[1] ); arr.$find( { arr: 0 }, false ).should.equals( arr[0] ); arr.$find( { arr: 0 }, Object.$equals ).should.equals( arr[1] ); // Pass in an array for lookup arr.$find( [ 'arr', 0 ] ).should.equals( arr[1] ); arr.$find( [ 'arr', 0 ], true ).should.equals( arr[1] ); arr.$find( [ 'arr', 0 ], false ).should.equals( arr[0] ); arr.$find( [ 'arr', 0 ], Object.$equals ).should.equals( arr[1] ); // Incoming object for lookup arr.$find( { arr: 0 }, 2 ).should.equals( arr[3] ); arr.$find( { arr: 0 }, true, 2 ).should.equals( arr[3] ); arr.$find( { arr: 0 }, false, 2 ).should.equals( arr[2] ); arr.$find( { arr: 0 }, Object.$equals, 2 ).should.equals( arr[3] ); // Pass in an array for lookup arr.$find( [ 'arr', 0 ], 2 ).should.equals( arr[3] ); arr.$find( [ 'arr', 0 ], true, 2 ).should.equals( arr[3] ); arr.$find( [ 'arr', 0 ], false, 2 ).should.equals( arr[2] ); arr.$find( [ 'arr', 0 ], Object.$equals, 2 ).should.equals( arr[3] ); } }, { name: 'Find non-pure objects in an array', it: function(){ var div = window.div; var span1 = window.span.$appendTo( div ).$html( '1' ); var span2 = window.span.$appendTo( div ).$html( '2' ); var span3 = window.span.$appendTo( div ).$html( '3' ); var span4 = window.span.$appendTo( div ).$html( '3' ); var span5 = window.span.$appendTo( div ).$html( '2' ); var span6 = window.span.$appendTo( div ).$html( '1' ); div.$find('span').$find([ 'innerHTML', '1' ]).should.equals( span1 ); div.$find('span').$find([ 'innerHTML', '2' ]).should.equals( span2 ); div.$find('span').$find([ 'innerHTML', '3' ]).should.equals( span3 ); div.$find('span').$find({ innerHTML: '1' }).should.equals( span1 ); div.$find('span').$find({ innerHTML: '2' }).should.equals( span2 ); div.$find('span').$find({ innerHTML: '3' }).should.equals( span3 ); div.$find('span').$find( [ 'innerHTML', '3' ], 3 ).should.equals( span4 ); div.$find('span').$find( [ 'innerHTML', '2' ], 3 ).should.equals( span5 ); div.$find('span').$find( [ 'innerHTML', '1' ], 3 ).should.equals( span6 ); div.$find('span').$find( { innerHTML: '3' }, 3 ).should.equals( span4 ); div.$find('span').$find( { innerHTML: '2' }, 3 ).should.equals( span5 ); div.$find('span').$find( { innerHTML: '1' }, 3 ).should.equals( span6 ); } } ] }, { name: '$findIndex', describe: [ { name: 'Traversing the contents of the collection using a custom method', it: function(){ var arr = [ 0, 1, 2, 3, 3 ]; Object.$equals( arr.$findIndex(function( value ){ return value === -4 }), -1 ).should.true; Object.$equals( arr.$findIndex(function( value ){ return value === -3 }), -1 ).should.true; Object.$equals( arr.$findIndex(function( value ){ return value === -2 }), -1 ).should.true; Object.$equals( arr.$findIndex(function( value ){ return value === -1 }), -1 ).should.true; Object.$equals( arr.$findIndex(function( value ){ return value }), 1 ).should.true; Object.$equals( arr.$findIndex(function( value ){ return value === 0 }), 0 ).should.true; Object.$equals( arr.$findIndex(function( value ){ return value === 1 }), 1 ).should.true; Object.$equals( arr.$findIndex(function( value ){ return value === 2 }), 2 ).should.true; Object.$equals( arr.$findIndex(function( value ){ return value === 3 }), 3 ).should.true; Object.$equals( arr.$findIndex(function( value ){ return value === 4 }), -1 ).should.true; var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; arr.$findIndex(function( obj ){ return obj.name }).should.equals( 0 ); arr.$findIndex(function( obj ){ return obj.type }).should.equals( 3 ); arr.$findIndex(function( obj ){ return obj.name && obj.type }).should.equals( 3 ); arr.$findIndex(function( obj ){ return obj.name == 'zenjs' }).should.equals( 1 ); arr.$findIndex(function( obj ){ return obj.name == 'zenui' }).should.equals( 2 ); arr.$findIndex(function( obj ){ return obj.type == 'js' }).should.equals( 3 ); arr.$findIndex(function( obj ){ return obj.type == 'ui' }).should.equals( 4 ); } }, { name: 'Incoming object for lookup', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; Object.$equals( arr.$findIndex({ name: 'xxx' }), -1 ).should.true; arr.$findIndex({ name: 'zen' }).should.equals( 0 ); arr.$findIndex({ name: 'zenjs' }).should.equals( 1 ); arr.$findIndex({ name: 'zenui' }).should.equals( 2 ); arr.$findIndex({ type: 'js' }).should.equals( 3 ); arr.$findIndex({ type: 'ui' }).should.equals( 4 ); arr.$findIndex({ name: 'zenjs', type: 'js' }).should.equals( 3 ); arr.$findIndex({ name: 'zenui', type: 'ui' }).should.equals( 4 ); } }, { name: 'Pass in an array for lookup', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; Object.$equals( arr.$findIndex([ 'name', 'xxx' ]), -1 ).should.true; arr.$findIndex([ 'name', 'zen' ]).should.equals( 0 ); arr.$findIndex([ 'name', 'zenjs' ]).should.equals( 1 ); arr.$findIndex([ 'name', 'zenui' ]).should.equals( 2 ); arr.$findIndex([ 'type', 'js' ]).should.equals( 3 ); arr.$findIndex([ 'type', 'ui' ]).should.equals( 4 ); arr.$findIndex([ 'name', 'zenjs', 'type', 'js' ]).should.equals( 3 ); arr.$findIndex([ 'name', 'zenui', 'type', 'ui' ]).should.equals( 4 ); } }, { name: 'Test the predicate parameter', it: function(){ var arr = [ { arr: false }, { arr: 0 } ]; // Incoming object for lookup arr.$findIndex( { arr: 0 } ).should.equals( 1 ); arr.$findIndex( { arr: 0 }, true ).should.equals( 1 ); arr.$findIndex( { arr: 0 }, false ).should.equals( 0 ); arr.$findIndex( { arr: 0 }, Object.$equals ).should.equals( 1 ); // Pass in an array for lookup arr.$findIndex( [ 'arr', 0 ] ).should.equals( 1 ); arr.$findIndex( [ 'arr', 0 ], true ).should.equals( 1 ); arr.$findIndex( [ 'arr', 0 ], false ).should.equals( 0 ); arr.$findIndex( [ 'arr', 0 ], Object.$equals ).should.equals( 1 ); } }, { name: 'Test the fromIndex parameter', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; // Traversing the contents of the collection using a custom method arr.$findIndex( function( obj ){ return obj.name }, 1 ).should.equals( 1 ); arr.$findIndex( function( obj ){ return obj.name == 'zenjs' }, 2 ).should.equals( 3 ); arr.$findIndex( function( obj ){ return obj.name == 'zenui' }, 3 ).should.equals( 4 ); // Incoming object for lookup Object.$equals( arr.$findIndex( { name: 'zen' }, 1 ), -1 ).should.true; arr.$findIndex( { name: 'zenjs' }, 2 ).should.equals( 3 ); arr.$findIndex( { name: 'zenui' }, 3 ).should.equals( 4 ); // Pass in an array for lookup Object.$equals( arr.$findIndex( [ 'name', 'zen' ], 1 ), -1 ).should.true; arr.$findIndex( [ 'name', 'zenjs' ], 2 ).should.equals( 3 ); arr.$findIndex( [ 'name', 'zenui' ], 3 ).should.equals( 4 ); } }, { name: 'Test the predicate parameter and fromIndex parameter', it: function(){ var arr = [ { arr: false }, { arr: 0 }, { arr: false }, { arr: 0 } ]; // Incoming object for lookup arr.$findIndex( { arr: 0 } ).should.equals( 1 ); arr.$findIndex( { arr: 0 }, true ).should.equals( 1 ); arr.$findIndex( { arr: 0 }, false ).should.equals( 0 ); arr.$findIndex( { arr: 0 }, Object.$equals ).should.equals( 1 ); // Pass in an array for lookup arr.$findIndex( [ 'arr', 0 ] ).should.equals( 1 ); arr.$findIndex( [ 'arr', 0 ], true ).should.equals( 1 ); arr.$findIndex( [ 'arr', 0 ], false ).should.equals( 0 ); arr.$findIndex( [ 'arr', 0 ], Object.$equals ).should.equals( 1 ); // Incoming object for lookup arr.$findIndex( { arr: 0 }, 2 ).should.equals( 3 ); arr.$findIndex( { arr: 0 }, true, 2 ).should.equals( 3 ); arr.$findIndex( { arr: 0 }, false, 2 ).should.equals( 2 ); arr.$findIndex( { arr: 0 }, Object.$equals, 2 ).should.equals( 3 ); // Pass in an array for lookup arr.$findIndex( [ 'arr', 0 ], 2 ).should.equals( 3 ); arr.$findIndex( [ 'arr', 0 ], true, 2 ).should.equals( 3 ); arr.$findIndex( [ 'arr', 0 ], false, 2 ).should.equals( 2 ); arr.$findIndex( [ 'arr', 0 ], Object.$equals, 2 ).should.equals( 3 ); } }, { name: 'Find non-pure objects in an array', it: function(){ var div = window.div; var span1 = window.span.$appendTo( div ).$html( '1' ); var span2 = window.span.$appendTo( div ).$html( '2' ); var span3 = window.span.$appendTo( div ).$html( '3' ); var span4 = window.span.$appendTo( div ).$html( '3' ); var span5 = window.span.$appendTo( div ).$html( '2' ); var span6 = window.span.$appendTo( div ).$html( '1' ); div.$find('span').$findIndex([ 'innerHTML', '1' ]).should.equals( 0 ); div.$find('span').$findIndex([ 'innerHTML', '2' ]).should.equals( 1 ); div.$find('span').$findIndex([ 'innerHTML', '3' ]).should.equals( 2 ); div.$find('span').$findIndex({ innerHTML: '1' }).should.equals( 0 ); div.$find('span').$findIndex({ innerHTML: '2' }).should.equals( 1 ); div.$find('span').$findIndex({ innerHTML: '3' }).should.equals( 2 ); div.$find('span').$findIndex( [ 'innerHTML', '3' ], 3 ).should.equals( 3 ); div.$find('span').$findIndex( [ 'innerHTML', '2' ], 3 ).should.equals( 4 ); div.$find('span').$findIndex( [ 'innerHTML', '1' ], 3 ).should.equals( 5 ); div.$find('span').$findIndex( { innerHTML: '3' }, 3 ).should.equals( 3 ); div.$find('span').$findIndex( { innerHTML: '2' }, 3 ).should.equals( 4 ); div.$find('span').$findIndex( { innerHTML: '1' }, 3 ).should.equals( 5 ); } } ] }, { name: '$findChunk', describe: [ { name: 'Traversing the contents of the collection using a custom method', it: function(){ var arr = [ 0, 1, 2, 3, 3 ]; Object.$equals( arr.$findChunk(function( value ){ return value === -4 }), undefined ).should.true; Object.$equals( arr.$findChunk(function( value ){ return value === -3 }), undefined ).should.true; Object.$equals( arr.$findChunk(function( value ){ return value === -2 }), undefined ).should.true; Object.$equals( arr.$findChunk(function( value ){ return value === -1 }), undefined ).should.true; Object.$equals( arr.$findChunk(function( value ){ return value }), [ 1, 1 ] ).should.true; Object.$equals( arr.$findChunk(function( value ){ return value === 0 }), [ 0, 0 ] ).should.true; Object.$equals( arr.$findChunk(function( value ){ return value === 1 }), [ 1, 1 ] ).should.true; Object.$equals( arr.$findChunk(function( value ){ return value === 2 }), [ 2, 2 ] ).should.true; Object.$equals( arr.$findChunk(function( value ){ return value === 3 }), [ 3, 3 ] ).should.true; Object.$equals( arr.$findChunk(function( value ){ return value === 4 }), undefined ).should.true; var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; Object.$equals( arr.$findChunk(function( obj ){ return obj.name }), [ 0, arr[0] ] ).should.true; Object.$equals( arr.$findChunk(function( obj ){ return obj.type }), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk(function( obj ){ return obj.name && obj.type }), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk(function( obj ){ return obj.name == 'zenjs' }), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk(function( obj ){ return obj.name == 'zenui' }), [ 2, arr[2] ] ).should.true; Object.$equals( arr.$findChunk(function( obj ){ return obj.type == 'js' }), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk(function( obj ){ return obj.type == 'ui' }), [ 4, arr[4] ] ).should.true; } }, { name: 'Incoming object for lookup', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; Object.$equals( arr.$findChunk({ name: 'xxx' }), undefined ).should.true; Object.$equals( arr.$findChunk({ name: 'zen' }), [ 0, arr[0] ] ).should.true; Object.$equals( arr.$findChunk({ name: 'zenjs' }), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk({ name: 'zenui' }), [ 2, arr[2] ] ).should.true; Object.$equals( arr.$findChunk({ type: 'js' }), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk({ type: 'ui' }), [ 4, arr[4] ] ).should.true; Object.$equals( arr.$findChunk({ name: 'zenjs', type: 'js' }), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk({ name: 'zenui', type: 'ui' }), [ 4, arr[4] ] ).should.true; } }, { name: 'Pass in an array for lookup', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; Object.$equals( arr.$findChunk([ 'name', 'xxx' ]), undefined ).should.true; Object.$equals( arr.$findChunk([ 'name', 'zen' ]), [ 0, arr[0] ] ).should.true; Object.$equals( arr.$findChunk([ 'name', 'zenjs' ]), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk([ 'name', 'zenui' ]), [ 2, arr[2] ] ).should.true; Object.$equals( arr.$findChunk([ 'type', 'js' ]), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk([ 'type', 'ui' ]), [ 4, arr[4] ] ).should.true; Object.$equals( arr.$findChunk([ 'name', 'zenjs', 'type', 'js' ]), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk([ 'name', 'zenui', 'type', 'ui' ]), [ 4, arr[4] ] ).should.true; } }, { name: 'Test the predicate parameter', it: function(){ var arr = [ { arr: false }, { arr: 0 } ]; // Incoming object for lookup Object.$equals( arr.$findChunk( { arr: 0 } ), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk( { arr: 0 }, true ), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk( { arr: 0 }, false ), [ 0, arr[0] ] ).should.true; Object.$equals( arr.$findChunk( { arr: 0 }, Object.$equals ), [ 1, arr[1] ] ).should.true; // Pass in an array for lookup Object.$equals( arr.$findChunk( [ 'arr', 0 ] ), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk( [ 'arr', 0 ], true ), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk( [ 'arr', 0 ], false ), [ 0, arr[0] ] ).should.true; Object.$equals( arr.$findChunk( [ 'arr', 0 ], Object.$equals ), [ 1, arr[1] ] ).should.true; } }, { name: 'Test the fromIndex parameter', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; // Traversing the contents of the collection using a custom method Object.$equals( arr.$findChunk( function( obj ){ return obj.name }, 1 ), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk( function( obj ){ return obj.name == 'zenjs' }, 2 ), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk( function( obj ){ return obj.name == 'zenui' }, 3 ), [ 4, arr[4] ] ).should.true; // Incoming object for lookup Object.$equals( arr.$findChunk( { name: 'zen' }, 1 ), undefined ).should.true; Object.$equals( arr.$findChunk( { name: 'zenjs' }, 2 ), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk( { name: 'zenui' }, 3 ), [ 4, arr[4] ] ).should.true; // Pass in an array for lookup Object.$equals( arr.$findChunk( [ 'name', 'zen' ], 1 ), undefined ).should.true; Object.$equals( arr.$findChunk( [ 'name', 'zenjs' ], 2 ), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk( [ 'name', 'zenui' ], 3 ), [ 4, arr[4] ] ).should.true; } }, { name: 'Test the predicate parameter and fromIndex parameter', it: function(){ var arr = [ { arr: false }, { arr: 0 }, { arr: false }, { arr: 0 } ]; // Incoming object for lookup Object.$equals( arr.$findChunk( { arr: 0 } ), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk( { arr: 0 }, true ), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk( { arr: 0 }, false ), [ 0, arr[0] ] ).should.true; Object.$equals( arr.$findChunk( { arr: 0 }, Object.$equals ), [ 1, arr[1] ] ).should.true; // Pass in an array for lookup Object.$equals( arr.$findChunk( [ 'arr', 0 ] ), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk( [ 'arr', 0 ], true ), [ 1, arr[1] ] ).should.true; Object.$equals( arr.$findChunk( [ 'arr', 0 ], false ), [ 0, arr[0] ] ).should.true; Object.$equals( arr.$findChunk( [ 'arr', 0 ], Object.$equals ), [ 1, arr[1] ] ).should.true; // Incoming object for lookup Object.$equals( arr.$findChunk( { arr: 0 }, 2 ), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk( { arr: 0 }, true, 2 ), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk( { arr: 0 }, false, 2 ), [ 2, arr[2] ] ).should.true; Object.$equals( arr.$findChunk( { arr: 0 }, Object.$equals, 2 ), [ 3, arr[3] ] ).should.true; // Pass in an array for lookup Object.$equals( arr.$findChunk( [ 'arr', 0 ], 2 ), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk( [ 'arr', 0 ], true, 2 ), [ 3, arr[3] ] ).should.true; Object.$equals( arr.$findChunk( [ 'arr', 0 ], false, 2 ), [ 2, arr[2] ] ).should.true; Object.$equals( arr.$findChunk( [ 'arr', 0 ], Object.$equals, 2 ), [ 3, arr[3] ] ).should.true; } }, { name: 'Find non-pure objects in an array', it: function(){ var div = window.div; var span1 = window.span.$appendTo( div ).$html( '1' ); var span2 = window.span.$appendTo( div ).$html( '2' ); var span3 = window.span.$appendTo( div ).$html( '3' ); var span4 = window.span.$appendTo( div ).$html( '3' ); var span5 = window.span.$appendTo( div ).$html( '2' ); var span6 = window.span.$appendTo( div ).$html( '1' ); Object.$equals( div.$find('span').$findChunk([ 'innerHTML', '1' ]), [ 0, span1 ] ).should.true; Object.$equals( div.$find('span').$findChunk([ 'innerHTML', '2' ]), [ 1, span2 ] ).should.true; Object.$equals( div.$find('span').$findChunk([ 'innerHTML', '3' ]), [ 2, span3 ] ).should.true; Object.$equals( div.$find('span').$findChunk({ innerHTML: '1' }), [ 0, span1 ] ).should.true; Object.$equals( div.$find('span').$findChunk({ innerHTML: '2' }), [ 1, span2 ] ).should.true; Object.$equals( div.$find('span').$findChunk({ innerHTML: '3' }), [ 2, span3 ] ).should.true; Object.$equals( div.$find('span').$findChunk( [ 'innerHTML', '3' ], 3 ), [ 3, span4 ] ).should.true; Object.$equals( div.$find('span').$findChunk( [ 'innerHTML', '2' ], 3 ), [ 4, span5 ] ).should.true; Object.$equals( div.$find('span').$findChunk( [ 'innerHTML', '1' ], 3 ), [ 5, span6 ] ).should.true; Object.$equals( div.$find('span').$findChunk( { innerHTML: '3' }, 3 ), [ 3, span4 ] ).should.true; Object.$equals( div.$find('span').$findChunk( { innerHTML: '2' }, 3 ), [ 4, span5 ] ).should.true; Object.$equals( div.$find('span').$findChunk( { innerHTML: '1' }, 3 ), [ 5, span6 ] ).should.true; } } ] }, { name: '$findLast', describe: [ { name: 'Traversing the contents of the collection using a custom method', it: function(){ var arr = [ 0, 1, 2, 3, 3 ]; Object.$equals( arr.$findLast(function( value ){ return value === -4 }), undefined ).should.true; Object.$equals( arr.$findLast(function( value ){ return value === -3 }), undefined ).should.true; Object.$equals( arr.$findLast(function( value ){ return value === -2 }), undefined ).should.true; Object.$equals( arr.$findLast(function( value ){ return value === -1 }), undefined ).should.true; Object.$equals( arr.$findLast(function( value ){ return value }), 3 ).should.true; Object.$equals( arr.$findLast(function( value ){ return value === 0 }), 0 ).should.true; Object.$equals( arr.$findLast(function( value ){ return value === 1 }), 1 ).should.true; Object.$equals( arr.$findLast(function( value ){ return value === 2 }), 2 ).should.true; Object.$equals( arr.$findLast(function( value ){ return value === 3 }), 3 ).should.true; Object.$equals( arr.$findLast(function( value ){ return value === 4 }), undefined ).should.true; var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; arr.$findLast(function( obj ){ return obj.name }).should.equals( arr[4] ); arr.$findLast(function( obj ){ return obj.type }).should.equals( arr[4] ); arr.$findLast(function( obj ){ return obj.name && obj.type }).should.equals( arr[4] ); arr.$findLast(function( obj ){ return obj.name == 'zenjs' }).should.equals( arr[3] ); arr.$findLast(function( obj ){ return obj.name == 'zenui' }).should.equals( arr[4] ); arr.$findLast(function( obj ){ return obj.type == 'js' }).should.equals( arr[3] ); arr.$findLast(function( obj ){ return obj.type == 'ui' }).should.equals( arr[4] ); } }, { name: 'Incoming object for lookup', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; Object.$equals( arr.$findLast({ name: 'xxx' }), undefined ).should.true; arr.$findLast({ name: 'zen' }).should.equals( arr[0] ); arr.$findLast({ name: 'zenjs' }).should.equals( arr[3] ); arr.$findLast({ name: 'zenui' }).should.equals( arr[4] ); arr.$findLast({ type: 'js' }).should.equals( arr[3] ); arr.$findLast({ type: 'ui' }).should.equals( arr[4] ); arr.$findLast({ name: 'zenjs', type: 'js' }).should.equals( arr[3] ); arr.$findLast({ name: 'zenui', type: 'ui' }).should.equals( arr[4] ); } }, { name: 'Pass in an array for lookup', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; Object.$equals( arr.$findLast([ 'name', 'xxx' ]), undefined ).should.true; arr.$findLast([ 'name', 'zen' ]).should.equals( arr[0] ); arr.$findLast([ 'name', 'zenjs' ]).should.equals( arr[3] ); arr.$findLast([ 'name', 'zenui' ]).should.equals( arr[4] ); arr.$findLast([ 'type', 'js' ]).should.equals( arr[3] ); arr.$findLast([ 'type', 'ui' ]).should.equals( arr[4] ); arr.$findLast([ 'name', 'zenjs', 'type', 'js' ]).should.equals( arr[3] ); arr.$findLast([ 'name', 'zenui', 'type', 'ui' ]).should.equals( arr[4] ); } }, { name: 'Test the predicate parameter', it: function(){ var arr = [ { arr: false }, { arr: 0 } ]; // Incoming object for lookup arr.$findLast( { arr: 0 } ).should.equals( arr[1] ); arr.$findLast( { arr: 0 }, true ).should.equals( arr[1] ); arr.$findLast( { arr: 0 }, false ).should.equals( arr[1] ); arr.$findLast( { arr: 0 }, Object.$equals ).should.equals( arr[1] ); // Pass in an array for lookup arr.$findLast( [ 'arr', 0 ] ).should.equals( arr[1] ); arr.$findLast( [ 'arr', 0 ], true ).should.equals( arr[1] ); arr.$findLast( [ 'arr', 0 ], false ).should.equals( arr[1] ); arr.$findLast( [ 'arr', 0 ], Object.$equals ).should.equals( arr[1] ); } }, { name: 'Test the fromIndex parameter', it: function(){ var arr = [ { name: 'zen' }, { name: 'zenjs' }, { name: 'zenui' }, { name: 'zenjs', type: 'js' }, { name: 'zenui', type: 'ui' } ]; // Traversing the contents of the collection using a custom method arr.$findLast( function( obj ){ return obj.name }, 1 ).should.equals( arr[1] ); arr.$findLast( function( obj ){ return obj.name == 'zenjs' }, 2 ).should.equals( arr[1] ); arr.$findLast( function( obj ){ return obj.name == 'zenui' }, 3 ).should.equals( arr[2] ); // Incoming object for lookup arr.$findLast( { name: 'zen' }, 1 ).should.equals( arr[0] ); arr.$findLast( { name: 'zenjs' }, 2 ).should.equals( arr[1] ); arr.$findLast( { name: 'zenui' }, 3 ).should.equals( arr[2] ); // Pass in an array for lookup arr.$findLast( [ 'name', 'zen' ], 1 ).should.equals( arr[0] ); arr.$findLast( [ 'name', 'zenjs' ], 2 ).should.equals( arr[1] ); arr.$findLast( [ 'name', 'zenui' ], 3 ).should.equals( arr[2] ); } }, { name: 'Test the predicate parameter and fromIndex parameter', it: function(){ var arr = [ { arr: false }, { arr: 0 }, { arr: false }, { arr: 0 } ]; // Incoming object for lookup arr.$findLast( { arr: 0 } ).should.equals( arr[3] ); arr.$findLast( { arr: 0 }, true ).should.equals( arr[3] ); arr.$findLast( { arr: 0 }, false ).should.equals( arr[3] ); arr.$findLast( { arr: 0 }, Object.$equals ).should.equals( arr[3] ); // Pass in an array for lookup arr.$findLast( [ 'arr', 0 ] ).should.equals( arr[3] ); arr.$findLast( [ 'arr', 0 ], true ).should.equals( arr[3] ); arr.$findLast( [ 'arr', 0 ], false ).should.equals( arr[3] ); arr.$findLast( [ 'arr', 0 ], Object.$equals ).should.equals( arr[3] ); // Incoming object for lookup arr.$findLast( { arr: 0 }, 2 ).should.equals( arr[1] ); arr.$findLast( { arr: 0 }, true, 2 ).should.equals( arr[1] ); arr.$findLast( { arr: 0 }, false, 2 ).should.equals( arr[2] ); arr.$findLast( { arr: 0 }, Object.$equals, 2 ).should.equals( arr[1] ); // Pass in an array for lookup arr.$findLast( [ 'arr', 0 ], 2 ).should.equals( arr[1] ); arr.$findLast( [ 'arr', 0 ], true, 2 ).should.equals( arr[1] ); arr.$findLast( [ 'arr', 0 ], false, 2 ).should.equals( arr[2] ); arr.$findLast( [ 'arr', 0 ], Object.$equals, 2 ).should.equals( arr[1] ); } }, { name: 'Find non-pure objects in an array', it: function(){ var div = window.div; var span1 = window.span.$appendTo( div ).$html( '1' ); var span2 = window.span.$appendTo( div ).$html( '2' ); var span3 = window.span.$appendTo( div ).$html( '3' ); var span4 = window.span.$appendTo( div ).$html( '3' ); var span5 = window.span.$appendTo( div ).$html( '2' ); var span6 = window.span.$appendTo( div ).$html( '1' ); div.$find('span').$findLast([ 'innerHTML', '1' ]).should.equals( span6 ); div.$find('span').$findLast([ 'innerHTML', '2' ]).should.equals( span5 ); div.$find('span').$findLast([ 'innerHTML', '3' ]).should.equals( span4 ); div.$find('span').$findLast({ innerHTML: '1' }).should.equals( span6 ); div.$find('span').$findLast({ innerHTML: '2' }).should.equals( span5 ); div.$find('span').$findLast({ innerHTML: '3' }).should.equals( span4 ); div.$find('span').$findLast( [ 'innerHTML', '3' ], 3 ).should.equals( span4 ); div.$find('span').$findLast( [ 'innerHTML', '2' ], 3 ).should.equals( span2 ); div.$find('span').$findLast( [ 'innerHTML', '1' ], 3 ).should.equals( span1 ); div.$find('span').$findLast(