Sorry, I got lost. I partially agree with Michael Luder-Rosefield. The main reason I started this thread is consistency. Because I can't get the logic behind what Michael listed above. I don't think I can support the idea of `iterOrder`. Looks like a try to create silver bullet and I don't think it's a handy way to perform these examples. Looks more universal than handy to me.
I like the idea to expand this proposal for `find` method as well. Thanks. P. S. This is my first proposal, so I apologies for bad formatting and forwarding. On Wed, 18 Jul 2018, 20:32 , <[email protected]> wrote: > Send es-discuss mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.mozilla.org/listinfo/es-discuss > or, via email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of es-discuss digest..." > Today's Topics: > > 1. Re: Ranges (Cyril Auburtin) > 2. Re: Feature proposal (T.J. Crowder) > 3. Re: Feature proposal (Michael Luder-Rosefield) > > > > ---------- Forwarded message ---------- > From: Cyril Auburtin <[email protected]> > To: es-discuss <[email protected]> > Cc: > Bcc: > Date: Wed, 18 Jul 2018 18:48:11 +0200 > Subject: Re: Ranges > I really like this possible new syntax for ranges: > > ```js > [2:9] // [2,3,4,5,6,7,8,9] > [1, 2, 4:7, 9] // [1, 2, 4, 5, 6, 7, 9] > [1:6:2] // [1, 3, 5] > ``` > > Would someone in TC39 be up to champion this? > > > > ---------- Forwarded message ---------- > From: "T.J. Crowder" <[email protected]> > To: Cyril Auburtin <[email protected]> > Cc: es-discuss <[email protected]> > Bcc: > Date: Wed, 18 Jul 2018 18:04:25 +0100 > Subject: Re: Feature proposal > On Wed, Jul 18, 2018 at 5:44 PM, Cyril Auburtin <[email protected]> > wrote: > > sorry you get 1, and need again to subtract the array length, > `arr.length -1 > > - 1` to get the final result 3 > > So you can't just use the passed-in third argument, and need: > > ```js > let a = [7, 4, 6, 7, 12]; > console.log(a.length - 1 - a.findIndex((_, i) => > isPrime(a[a.length-1-i]))); > ``` > > Strikes me as a reasonable argument for adding `findLastIndex`. ;-) (And > perhaps `findLast`, since the same trick with `find` just won't work at > all.) > > Prior art (looking for instance at the libs that inspired the array > additions in ES5 and ES2015): > * Lodash implements both `findLastIndex` and `findLast`). > * Underscore, PrototypeJS, and MooTools don't as far as I can see from the > docs. > > -- T.J. Crowder > > > > ---------- Forwarded message ---------- > From: Michael Luder-Rosefield <[email protected]> > To: Cyril Auburtin <[email protected]> > Cc: es-discuss <[email protected]> > Bcc: > Date: Wed, 18 Jul 2018 18:31:41 +0100 > Subject: Re: Feature proposal > Is strikes me that every single Array method that takes an iteratee > function (signature (value, index, array)) should be able to iterate > through the array in reverse, in a standardised way. > > At the moment, we have: > > - every > - filter > - find > - findIndex > - forEach > - indexOf / lastIndexOf > - map > - reduce / reduceRight > - some > > which is not very consistent at all. Perhaps we could add an `iterOrder` > method that changes the way the array is iterated through? > > I propose it could take 1 parameter: > > - If -1 is passed in, the array is iterated through in reverse. > - If 1,0 or undefined is passed through, the array is iterated through > normally. > - If an array of numbers is passed through, these represent the > indexes in the order they will be processed. > - Any illegible indexes in the passed-in array will be ignored > - Any eligible indexes not given will be ignored > - If a generator function is passed in, it should take the array (or a > length value) and spit out indexes. > - If a non-generator function is passed in, it should spit out an > array of indexes, which will be used as-per arrays being passed in > > Whether that iterOrder is reset after an iteration could go either way. > I'd suggest it probably should, with an option to persist. > > Example: > > ``` > let arr = [ 8,4,7,3 ]; > > arr.iterOrder().map(x => x) === arr > arr.iterOrder(-1).map(x => x) === arr.reverse() === [ 3,7,4,8 ] > arr.iterOrder([ 2,1 ]).map(x => x) === [ 7,4 ] > // haven't got time to give function arg examples, but randomisers would > be fairly trivial > > // original indexes are preserved during iteration: > arr.iterOrder(-1).forEach((val, i) => console.log(val, i)) > // > 3, 3 > // > 7, 2 > // > 4, 1 > // > 8, 0 > ``` > > This is a messy first-pass at the problem, and I can already see potential > issues, but it would at least standardise and generalise the problem > > > > On Wed, 18 Jul 2018 at 17:44 Cyril Auburtin <[email protected]> > wrote: > >> sorry you get 1, and need again to subtract the array length, `arr.length >> -1 - 1` to get the final result 3 >> >> Le mer. 18 juil. 2018 à 18:41, Cyril Auburtin <[email protected]> >> a écrit : >> >>> there you go >>> ``` >>> console.log([7, 4, 6, 7, 12].findIndex((_, i, a) => >>> isPrime(a[a.length-1-i]))); // 3 >>> ``` >>> >>> Le mer. 18 juil. 2018 à 11:17, Dmitry Shulgin <[email protected]> a >>> écrit : >>> >>>> >>>> ---------- Forwarded message ---------- >>>> From: Dmitry Shulgin <[email protected]> >>>> Date: 2018-07-05 10:36 GMT+03:00 >>>> Subject: Feature proposal >>>> To: [email protected] >>>> >>>> >>>> I came across a task of finding an index of the last element in array >>>> that satisfies the condition, so i reversed array and found it by >>>> *findIndex >>>> *function. >>>> I was thinking: >>>> Why do we have *findIndex*` method, but no *findLastIndex*? >>>> It seems logical to follow *[index|lastIndex]Of* pair, doesn't it? >>>> Reversing array in this case seems too complicated to me. >>>> >>>> So, i would like to suggest new method like >>>> *Array.prototype.findLastIndex()* >>>> >>>> Example: >>>> >>>> function isPrime(element, index, array) { >>>> var start = 2; >>>> while (start <= Math.sqrt(element)) { >>>> if (element % start++ < 1) { >>>> return false; >>>> } >>>> } >>>> return element > 1; >>>> } >>>> >>>> console.log([4, 6, 8, 12].findIndex(isPrime)); // -1, not found >>>> console.log([7, 4, 6, 7, 12].findIndexLast(isPrime)); // 3 >>>> >>>> >>>> Would be glad to implement, if it makes sense. >>>> >>>> Thx for replies. >>>> >>>> P.S. Small issue on GitHub was closed due to offtop (not an issue, as i >>>> understand). >>>> https://github.com/tc39/ecma262/issues/1253 >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> [email protected] >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

