@@ -191,8 +191,8 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
191191 setNonEnumerableProperty ( tuple , 'fieldOf' , fieldOf ) ;
192192 setNonEnumerableProperty ( tuple , 'filter' , filter ) ;
193193 setNonEnumerableProperty ( tuple , 'find' , find ) ;
194- setNonEnumerableProperty ( tuple , 'findIndex' , findIndex ) ;
195194 setNonEnumerableProperty ( tuple , 'findField' , findField ) ;
195+ setNonEnumerableProperty ( tuple , 'findIndex' , findIndex ) ;
196196 setNonEnumerableProperty ( tuple , 'findLast' , findLast ) ;
197197 setNonEnumerableProperty ( tuple , 'findLastField' , findLastField ) ;
198198 setNonEnumerableProperty ( tuple , 'findLastIndex' , findLastIndex ) ;
@@ -557,21 +557,21 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
557557 }
558558
559559 /**
560- * Returns the last tuple element for which a provided predicate function returns a truthy value.
560+ * Returns the index of the first tuple element for which a provided predicate function returns a truthy value.
561561 *
562562 * ## Notes
563563 *
564- * - The method iterates from right to left .
564+ * - If the predicate function never returns a truthy value, the function returns `-1` .
565565 *
566566 * @private
567567 * @memberof tuple
568568 * @param {Function } predicate - predicate function
569569 * @param {* } [thisArg] - execution context
570570 * @throws {TypeError } `this` must be the host tuple
571571 * @throws {TypeError } first argument must be a function
572- * @returns {(number|void) } tuple element
572+ * @returns {integer } tuple index or `-1`
573573 */
574- function findLast ( predicate , thisArg ) {
574+ function findIndex ( predicate , thisArg ) {
575575 var bool ;
576576 var i ;
577577 if ( this !== tuple ) { // eslint-disable-line no-invalid-this
@@ -580,33 +580,32 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
580580 if ( ! isFunction ( predicate ) ) {
581581 throw new TypeError ( format ( 'invalid argument. First argument must be a function. Value: `%s`.' , predicate ) ) ;
582582 }
583- for ( i = nfields - 1 ; i >= 0 ; i -- ) {
583+ for ( i = 0 ; i < nfields ; i ++ ) {
584584 bool = predicate . call ( thisArg , tuple [ i ] , i , fields [ indices [ i ] ] , tuple ) ;
585585 if ( bool ) {
586- return tuple [ i ] ;
586+ return i ;
587587 }
588588 }
589+ return - 1 ;
589590 }
590591
591592 /**
592- * Returns the field of the last tuple element for which a provided predicate function returns a truthy value.
593+ * Returns the last tuple element for which a provided predicate function returns a truthy value.
593594 *
594595 * ## Notes
595596 *
596597 * - The method iterates from right to left.
597- * - If the predicate function never returns a truthy value, the function returns `undefined`.
598598 *
599599 * @private
600600 * @memberof tuple
601601 * @param {Function } predicate - predicate function
602602 * @param {* } [thisArg] - execution context
603603 * @throws {TypeError } `this` must be the host tuple
604604 * @throws {TypeError } first argument must be a function
605- * @returns {(string |void) } tuple field name or `undefined`
605+ * @returns {(number |void) } tuple element
606606 */
607- function findLastField ( predicate , thisArg ) {
607+ function findLast ( predicate , thisArg ) {
608608 var bool ;
609- var f ;
610609 var i ;
611610 if ( this !== tuple ) { // eslint-disable-line no-invalid-this
612611 throw new TypeError ( 'invalid invocation. `this` is not host tuple.' ) ;
@@ -615,32 +614,32 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
615614 throw new TypeError ( format ( 'invalid argument. First argument must be a function. Value: `%s`.' , predicate ) ) ;
616615 }
617616 for ( i = nfields - 1 ; i >= 0 ; i -- ) {
618- f = fields [ indices [ i ] ] ;
619- bool = predicate . call ( thisArg , tuple [ i ] , i , f , tuple ) ;
617+ bool = predicate . call ( thisArg , tuple [ i ] , i , fields [ indices [ i ] ] , tuple ) ;
620618 if ( bool ) {
621- return f ;
619+ return tuple [ i ] ;
622620 }
623621 }
624622 }
625623
626624 /**
627- * Returns the index of the last tuple element for which a provided predicate function returns a truthy value.
625+ * Returns the field of the last tuple element for which a provided predicate function returns a truthy value.
628626 *
629627 * ## Notes
630628 *
631629 * - The method iterates from right to left.
632- * - If the predicate function never returns a truthy value, the function returns `-1 `.
630+ * - If the predicate function never returns a truthy value, the function returns `undefined `.
633631 *
634632 * @private
635633 * @memberof tuple
636634 * @param {Function } predicate - predicate function
637635 * @param {* } [thisArg] - execution context
638636 * @throws {TypeError } `this` must be the host tuple
639637 * @throws {TypeError } first argument must be a function
640- * @returns {integer } tuple index or `-1 `
638+ * @returns {(string|void) } tuple field name or `undefined `
641639 */
642- function findLastIndex ( predicate , thisArg ) {
640+ function findLastField ( predicate , thisArg ) {
643641 var bool ;
642+ var f ;
644643 var i ;
645644 if ( this !== tuple ) { // eslint-disable-line no-invalid-this
646645 throw new TypeError ( 'invalid invocation. `this` is not host tuple.' ) ;
@@ -649,19 +648,20 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
649648 throw new TypeError ( format ( 'invalid argument. First argument must be a function. Value: `%s`.' , predicate ) ) ;
650649 }
651650 for ( i = nfields - 1 ; i >= 0 ; i -- ) {
652- bool = predicate . call ( thisArg , tuple [ i ] , i , fields [ indices [ i ] ] , tuple ) ;
651+ f = fields [ indices [ i ] ] ;
652+ bool = predicate . call ( thisArg , tuple [ i ] , i , f , tuple ) ;
653653 if ( bool ) {
654- return i ;
654+ return f ;
655655 }
656656 }
657- return - 1 ;
658657 }
659658
660659 /**
661- * Returns the index of the first tuple element for which a provided predicate function returns a truthy value.
660+ * Returns the index of the last tuple element for which a provided predicate function returns a truthy value.
662661 *
663662 * ## Notes
664663 *
664+ * - The method iterates from right to left.
665665 * - If the predicate function never returns a truthy value, the function returns `-1`.
666666 *
667667 * @private
@@ -672,7 +672,7 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
672672 * @throws {TypeError } first argument must be a function
673673 * @returns {integer } tuple index or `-1`
674674 */
675- function findIndex ( predicate , thisArg ) {
675+ function findLastIndex ( predicate , thisArg ) {
676676 var bool ;
677677 var i ;
678678 if ( this !== tuple ) { // eslint-disable-line no-invalid-this
@@ -681,7 +681,7 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
681681 if ( ! isFunction ( predicate ) ) {
682682 throw new TypeError ( format ( 'invalid argument. First argument must be a function. Value: `%s`.' , predicate ) ) ;
683683 }
684- for ( i = 0 ; i < nfields ; i ++ ) {
684+ for ( i = nfields - 1 ; i >= 0 ; i -- ) {
685685 bool = predicate . call ( thisArg , tuple [ i ] , i , fields [ indices [ i ] ] , tuple ) ;
686686 if ( bool ) {
687687 return i ;
0 commit comments