add reverse() method to strings
Be aware your code breaks pair surrogates, which might be undesirable:
var str = "a_\uD83D\uDE80_b";
str.split("").reverse().join(""); // "b_\uDE80\uD83D_a" :(
[...str].reverse().join(""); // "b_\uD83D\uDE80_a" :)
Be aware your code breaks pair surrogates, which might be undesirable: ```js var str = "a_\uD83D\uDE80_b"; str.split("").reverse().join(""); // "b_\uDE80\uD83D_a" :( [...str].reverse().join(""); // "b_\uD83D\uDE80_a" :) ``` --Oriol -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180317/8054c6b7/attachment.html>
Le 17 mars 2018 à 19:29, Oriol _ <oriol-bugzilla at hotmail.com> a écrit :
Be aware your code breaks pair surrogates, which might be undesirable:
var str = "a_\uD83D\uDE80_b"; str.split("").reverse().join(""); // "b_\uDE80\uD83D_a" :( [...str].reverse().join(""); // "b_\uD83D\uDE80_a" :)
—Oriol
Well, but be aware that the corrected implementation still breaks graphemes composed by a sequence of code points, such as: n̈ ( LATIN SMALL LETTER N + COMBINING DIEARESIS), which might be undesirable...
Anyway, what are the use cases?
> Le 17 mars 2018 à 19:29, Oriol _ <oriol-bugzilla at hotmail.com> a écrit : > > Be aware your code breaks pair surrogates, which might be undesirable: > > ```js > var str = "a_\uD83D\uDE80_b"; > str.split("").reverse().join(""); // "b_\uDE80\uD83D_a" :( > [...str].reverse().join(""); // "b_\uD83D\uDE80_a" :) > ``` > > —Oriol Well, but be aware that the corrected implementation still breaks graphemes composed by a sequence of code points, such as: n̈ ( LATIN SMALL LETTER N + COMBINING DIEARESIS), which might be undesirable... Anyway, what are the use cases? —Claude -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180317/f0587126/attachment-0001.html>
String.prototype.reverse() might break web compatibility, how about String.prototype.turnyRoundy()?
String.prototype.reverse() might break web compatibility, how about String.prototype.turnyRoundy()? On 17 Mar 2018 18:47, "Claude Pache" <claude.pache at gmail.com> wrote: > > > Le 17 mars 2018 à 19:29, Oriol _ <oriol-bugzilla at hotmail.com> a écrit : > > Be aware your code breaks pair surrogates, which might be undesirable: > > ```js > var str = "a_\uD83D\uDE80_b"; > str.split("").reverse().join(""); // "b_\uDE80\uD83D_a" :( > [...str].reverse().join(""); // "b_\uD83D\uDE80_a" :) > ``` > > —Oriol > > > Well, but be aware that the corrected implementation still breaks > graphemes composed by a sequence of code points, such as: n̈ ( LATIN SMALL > LETTER N + COMBINING DIEARESIS), which might be undesirable... > > Anyway, what are the use cases? > > —Claude > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180317/12cc15c6/attachment.html>
I would use Array.from
:
str = "a_\uD83D\uDE80_b"
Array.from(str).reverse().join('')
But I also upvote the idea of having a reverse method in strings :)
If reverse
might cause some retrocompatibility problem (although I don't
think it requires params, what would pretty much avoid different
implementations as the method itself is very straight forwards), we could
go for reverseText
or reverseContent
.
.o/
[ ]s
--
Felipe N. Moura Web Developer, Google Developer Expert developers.google.com/experts/people/felipe-moura, Founder of
BrazilJS braziljs.org and Nasc nasc.io.
Website: felipenmoura.com / nasc.io Twitter: @felipenmoura twitter.com/felipenmoura
Facebook: fb.com/felipenmoura LinkedIn: goo.gl/qGmq
Changing the world is the least I expect from myself!
I would use `Array.from`: ``` str = "a_\uD83D\uDE80_b" Array.from(str).reverse().join('') ``` But I also upvote the idea of having a reverse method in strings :) If `reverse` might cause some retrocompatibility problem (although I don't think it requires params, what would pretty much avoid different implementations as the method itself is very straight forwards), we could go for `reverseText` or `reverseContent`. .o/ [ ]s *--* *Felipe N. Moura* Web Developer, Google Developer Expert <https://developers.google.com/experts/people/felipe-moura>, Founder of BrazilJS <https://braziljs.org/> and Nasc <http://nasc.io/>. Website: http://felipenmoura.com / http://nasc.io/ Twitter: @felipenmoura <http://twitter.com/felipenmoura> Facebook: http://fb.com/felipenmoura LinkedIn: http://goo.gl/qGmq --------------------------------- *Changing the world* is the least I expect from myself! On Sat, Mar 17, 2018 at 4:48 PM, Thomas Grainger <tagrain at gmail.com> wrote: > String.prototype.reverse() might break web compatibility, how about > String.prototype.turnyRoundy()? > > On 17 Mar 2018 18:47, "Claude Pache" <claude.pache at gmail.com> wrote: > >> >> >> Le 17 mars 2018 à 19:29, Oriol _ <oriol-bugzilla at hotmail.com> a écrit : >> >> Be aware your code breaks pair surrogates, which might be undesirable: >> >> ```js >> var str = "a_\uD83D\uDE80_b"; >> str.split("").reverse().join(""); // "b_\uDE80\uD83D_a" :( >> [...str].reverse().join(""); // "b_\uD83D\uDE80_a" :) >> ``` >> >> —Oriol >> >> >> Well, but be aware that the corrected implementation still breaks >> graphemes composed by a sequence of code points, such as: n̈ ( LATIN SMALL >> LETTER N + COMBINING DIEARESIS), which might be undesirable... >> >> Anyway, what are the use cases? >> >> —Claude >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180317/54360c3f/attachment.html>
Other than for amusement or programming challenge I've never found a use for it? Do you have one?
Other than for amusement or programming challenge I've never found a use for it? Do you have one? On Sat, Mar 17, 2018 at 4:11 PM, Felipe Nascimento de Moura < felipenmoura at gmail.com> wrote: > I would use `Array.from`: > > ``` > str = "a_\uD83D\uDE80_b" > Array.from(str).reverse().join('') > ``` > > But I also upvote the idea of having a reverse method in strings :) > > If `reverse` might cause some retrocompatibility problem (although I don't > think it requires params, what would pretty much avoid different > implementations as the method itself is very straight forwards), we could > go for `reverseText` or `reverseContent`. > > .o/ > > > > [ ]s > > *--* > > *Felipe N. Moura* > Web Developer, Google Developer Expert > <https://developers.google.com/experts/people/felipe-moura>, Founder of > BrazilJS <https://braziljs.org/> and Nasc <http://nasc.io/>. > > Website: http://felipenmoura.com / http://nasc.io/ > Twitter: @felipenmoura <http://twitter.com/felipenmoura> > Facebook: http://fb.com/felipenmoura > LinkedIn: http://goo.gl/qGmq > --------------------------------- > *Changing the world* is the least I expect from myself! > > On Sat, Mar 17, 2018 at 4:48 PM, Thomas Grainger <tagrain at gmail.com> > wrote: > >> String.prototype.reverse() might break web compatibility, how about >> String.prototype.turnyRoundy()? >> >> On 17 Mar 2018 18:47, "Claude Pache" <claude.pache at gmail.com> wrote: >> >>> >>> >>> Le 17 mars 2018 à 19:29, Oriol _ <oriol-bugzilla at hotmail.com> a écrit : >>> >>> Be aware your code breaks pair surrogates, which might be undesirable: >>> >>> ```js >>> var str = "a_\uD83D\uDE80_b"; >>> str.split("").reverse().join(""); // "b_\uDE80\uD83D_a" :( >>> [...str].reverse().join(""); // "b_\uD83D\uDE80_a" :) >>> ``` >>> >>> —Oriol >>> >>> >>> Well, but be aware that the corrected implementation still breaks >>> graphemes composed by a sequence of code points, such as: n̈ ( LATIN SMALL >>> LETTER N + COMBINING DIEARESIS), which might be undesirable... >>> >>> Anyway, what are the use cases? >>> >>> —Claude >>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180317/94ebcb82/attachment-0001.html>
Previous discussion: esdiscuss.org/topic/wiki-updates-for-string-number-and-math-libraries#content-1
""" String.prototype.reverse(), as proposed, corrupts supplementary characters. Clause 6 of Ecma-262 redefines the word "character" as "a 16-bit unsigned value used to represent a single 16-bit unit of text", that is, a UTF-16 code unit. In contrast, the phrase "Unicode character" is used for Unicode code points. For reverse(), this means that the proposed spec will reverse the sequence of the two UTF-16 code units representing a supplementary character, resulting in corruption. If this function is really needed (is it? for what?), it should preserve the order of surrogate pairs, as does java.lang.StringBuilder.reverse: download.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html#reverse() """
Previous discussion: https://esdiscuss.org/topic/wiki-updates-for-string-number-and-math-libraries#content-1 """ String.prototype.reverse(), as proposed, corrupts supplementary characters. Clause 6 of Ecma-262 redefines the word "character" as "a 16-bit unsigned value used to represent a single 16-bit unit of text", that is, a UTF-16 code unit. In contrast, the phrase "Unicode character" is used for Unicode code points. For reverse(), this means that the proposed spec will reverse the sequence of the two UTF-16 code units representing a supplementary character, resulting in corruption. If this function is really needed (is it? for what?), it should preserve the order of surrogate pairs, as does java.lang.StringBuilder.reverse: download.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html#reverse() """ On Sat, Mar 17, 2018 at 1:41 PM, Grigory Hatsevich <g.hatsevich at gmail.com> wrote: > Hi! I would propose to add reverse() method to strings. Something > equivalent to the following: > > String.prototype.reverse = function(){ > return this.split('').reverse().join('') > } > > It seems natural to have such method. Why not? > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180317/0481cafa/attachment.html>
So far no one has provided a real-world use case.
So far no one has provided a real-world use case. On Mar 18, 2018 10:15, "Mike Samuel" <mikesamuel at gmail.com> wrote: > Previous discussion: https://esdiscuss.org/topic/wiki-updates-for-string- > number-and-math-libraries#content-1 > > """ > String.prototype.reverse(), as proposed, corrupts supplementary > characters. Clause 6 of Ecma-262 redefines the word "character" as "a > 16-bit unsigned value used to represent a single 16-bit unit of text", that > is, a UTF-16 code unit. In contrast, the phrase "Unicode character" is used > for Unicode code points. For reverse(), this means that the proposed spec > will reverse the sequence of the two UTF-16 code units representing a > supplementary character, resulting in corruption. If this function is > really needed (is it? for what?), it should preserve the order of surrogate > pairs, as does java.lang.StringBuilder.reverse:download.oracle.com/ > javase/7/docs/api/java/lang/StringBuilder.html#reverse() > """ > > On Sat, Mar 17, 2018 at 1:41 PM, Grigory Hatsevich <g.hatsevich at gmail.com> > wrote: > >> Hi! I would propose to add reverse() method to strings. Something >> equivalent to the following: >> >> String.prototype.reverse = function(){ >> return this.split('').reverse().join('') >> } >> >> It seems natural to have such method. Why not? >> > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180318/e6bb8517/attachment.html>
My use case is solving coding tasks about palindromes on codefights.com.
Not sure if that counts as "real-world", but probably a lot of beginning
developers encounter such tasks at least once.
My use case is solving coding tasks about palindromes on codefights.com. Not sure if that counts as "real-world", but probably a lot of beginning developers encounter such tasks at least once. On Sun, 18 Mar 2018 06:41:46 +0700, Mathias Bynens <mathias at qiwi.be> wrote: > So far no one has provided a real-world use case. > > On Mar 18, 2018 10:15, "Mike Samuel" <mikesamuel at gmail.com> wrote: >> Previous discussion: >> https://esdiscuss.org/topic/wiki-updates-for-string-number-and-math->>libraries#content-1 >> >> """ >> String.prototype.reverse(), as proposed, corrupts supplementary >> characters. >>Clause 6 of Ecma-262 redefines the word "character" as "a >> 16-bit unsigned >>value used to represent a single 16-bit unit of >> text", that is, a UTF-16 code >>unit. In contrast, the phrase "Unicode >> character" is used for Unicode code >>points. For reverse(), this means >> that the proposed spec will reverse the >>sequence of the two UTF-16 >> code units representing a supplementary >>character, resulting in >> corruption. If this function is really needed (is it? for >>what?), it >> should preserve the order of surrogate pairs, as does >> >>java.lang.StringBuilder.reverse:download.oracle.com/javase/7/docs/api/>>java/lang/StringBuilder.html#reverse() >> """ >> >> On Sat, Mar 17, 2018 at 1:41 PM, Grigory Hatsevich >> <g.hatsevich at gmail.com> wrote: >>> Hi! I would propose to add reverse() method to strings. Something >>> equivalent to the following: >>> >>> String.prototype.reverse = function(){ >>> return this.split('').reverse().join('') >>> } >>> >>> It seems natural to have such method. Why not? >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180318/5b686f87/attachment-0001.html>
The point of a coding task for a beginner is to practice their problem solving skills to solve the task. This would remove the challenge and actively worsen their learning process
The point of a coding task for a beginner is to practice their problem solving skills to solve the task. This would remove the challenge and actively worsen their learning process On Mar 18 2018, at 6:26 pm, Grigory Hatsevich <g.hatsevich at gmail.com> wrote: > > My use case is solving coding tasks about palindromes on codefights.com. Not sure if that counts as "real-world", but probably a lot of beginning developers encounter such tasks at least once. > > > > > On Sun, 18 Mar 2018 06:41:46 +0700, Mathias Bynens <mathias at qiwi.be> wrote: > > So far no one has provided a real-world use case. > > > > On Mar 18, 2018 10:15, "Mike Samuel" <mikesamuel at gmail.com (https://link.getmailspring.com/link/[email protected]/0?redirect=mailto%3Amikesamuel%40gmail.com&recipient=ZXMtZGlzY3Vzc0Btb3ppbGxhLm9yZw%3D%3D)> wrote: > > > Previous discussion: https://esdiscuss.org/topic/wiki-updates-for-string-number-and-math-libraries#content-1 (https://link.getmailspring.com/link/[email protected]/1?redirect=https%3A%2F%2Fesdiscuss.org%2Ftopic%2Fwiki-updates-for-string-number-and-math-libraries%23content-1&recipient=ZXMtZGlzY3Vzc0Btb3ppbGxhLm9yZw%3D%3D) > > > > > > """ > > > String.prototype.reverse(), as proposed, corrupts supplementary characters. Clause 6 of Ecma-262 redefines the word "character" as "a 16-bit unsigned value used to represent a single 16-bit unit of text", that is, a UTF-16 code unit. In contrast, the phrase "Unicode character" is used for Unicode code points. For reverse(), this means that the proposed spec will reverse the sequence of the two UTF-16 code units representing a supplementary character, resulting in corruption. If this function is really needed (is it? for what?), it should preserve the order of surrogate pairs, as does java.lang.StringBuilder.reverse:download.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html#reverse() (https://link.getmailspring.com/link/[email protected]/2?redirect=http%3A%2F%2Fdownload.oracle.com%2Fjavase%2F7%2Fdocs%2Fapi%2Fjava%2Flang%2FStringBuilder.html%23reverse()&recipient=ZXMtZGlzY3Vzc0Btb3ppbGxhLm9yZw%3D%3D) > > > """ > > > > > > On Sat, Mar 17, 2018 at 1:41 PM, Grigory Hatsevich <g.hatsevich at gmail.com (https://link.getmailspring.com/link/[email protected]/3?redirect=mailto%3Ag.hatsevich%40gmail.com&recipient=ZXMtZGlzY3Vzc0Btb3ppbGxhLm9yZw%3D%3D)> wrote: > > > > Hi! I would propose to add reverse() method to strings. Something > > > > equivalent to the following: > > > > > > > > String.prototype.reverse = function(){ > > > > return this.split('').reverse().join('') > > > > } > > > > > > > > It seems natural to have such method. Why not? > > > > > > > > > _______________________________________________ > > > es-discuss mailing list > > > es-discuss at mozilla.org (https://link.getmailspring.com/link/[email protected]/4?redirect=mailto%3Aes-discuss%40mozilla.org&recipient=ZXMtZGlzY3Vzc0Btb3ppbGxhLm9yZw%3D%3D) > > > https://mail.mozilla.org/listinfo/es-discuss (https://link.getmailspring.com/link/[email protected]/5?redirect=https%3A%2F%2Fmail.mozilla.org%2Flistinfo%2Fes-discuss&recipient=ZXMtZGlzY3Vzc0Btb3ppbGxhLm9yZw%3D%3D) > > > > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180318/2843b92a/attachment.html>
"This would remove the challenge and actively worsen their learning process" -- this is not true. You can see it e.g. by looking at the specific task I was talking about:
"Given a string, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome."
This is my code for this task:
function buildPalindrome(s){
String.prototype.reverse=function(){
return this.split('').reverse().join('')
}
function isPalindrome(s){
return s===s.reverse()
}
for (i=0;i<s.length;i++){
first=s.slice(0,i);
rest=s.slice(i);
if(isPalindrome(rest)){
return s+first.reverse()
}
}
}
As you see, the essence of this challenge is not in the process of reversing a string. Having a reverse() method just makes the code more readable -- comparing to alternative when one would have to write .split('').reverse().join('') each time instead of just .reverse()
"This would remove the challenge and actively worsen their learning process" -- this is not true. You can see it e.g. by looking at the specific task I was talking about: "Given a string, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome." This is my code for this task: function buildPalindrome(s){ String.prototype.reverse=function(){ return this.split('').reverse().join('') } function isPalindrome(s){ return s===s.reverse() } for (i=0;i<s.length;i++){ first=s.slice(0,i); rest=s.slice(i); if(isPalindrome(rest)){ return s+first.reverse() } } } As you see, the essence of this challenge is not in the process of reversing a string. Having a reverse() method just makes the code more readable -- comparing to alternative when one would have to write .split('').reverse().join('') each time instead of just .reverse() On Sun, Mar 18, 2018 at 2:38 PM, Frederick Stark <coagmano at gmail.com> wrote: > The point of a coding task for a beginner is to practice their problem > solving skills to solve the task. This would remove the challenge and > actively worsen their learning process > > > On Mar 18 2018, at 6:26 pm, Grigory Hatsevich <g.hatsevich at gmail.com> > wrote: > > > My use case is solving coding tasks about palindromes on codefights.com. > Not sure if that counts as "real-world", but probably a lot of beginning > developers encounter such tasks at least once. > > > > > On Sun, 18 Mar 2018 06:41:46 +0700, Mathias Bynens <mathias at qiwi.be> > wrote: > > So far no one has provided a real-world use case. > > On Mar 18, 2018 10:15, "Mike Samuel" <mikesamuel at gmail.com > <https://link.getmailspring.com/link/[email protected]/0?redirect=mailto%3Amikesamuel%40gmail.com&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> > wrote: > > Previous discussion: https://esdiscuss.org/topic/wiki-updates-for-string- > number-and-math-libraries#content-1 > <https://link.getmailspring.com/link/[email protected]/1?redirect=https%3A%2F%2Fesdiscuss.org%2Ftopic%2Fwiki-updates-for-string-number-and-math-libraries%23content-1&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> > > """ > String.prototype.reverse(), as proposed, corrupts supplementary > characters. Clause 6 of Ecma-262 redefines the word "character" as "a > 16-bit unsigned value used to represent a single 16-bit unit of text", that > is, a UTF-16 code unit. In contrast, the phrase "Unicode character" is used > for Unicode code points. For reverse(), this means that the proposed spec > will reverse the sequence of the two UTF-16 code units representing a > supplementary character, resulting in corruption. If this function is > really needed (is it? for what?), it should preserve the order of surrogate > pairs, as does java.lang.StringBuilder.reverse:download.oracle.com/ > javase/7/docs/api/java/lang/StringBuilder.html#reverse() > <https://link.getmailspring.com/link/[email protected]/2?redirect=http%3A%2F%2Fdownload.oracle.com%2Fjavase%2F7%2Fdocs%2Fapi%2Fjava%2Flang%2FStringBuilder.html%23reverse()&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> > """ > > On Sat, Mar 17, 2018 at 1:41 PM, Grigory Hatsevich <g.hatsevich at gmail.com > <https://link.getmailspring.com/link/[email protected]/3?redirect=mailto%3Ag.hatsevich%40gmail.com&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> > wrote: > > Hi! I would propose to add reverse() method to strings. Something > equivalent to the following: > > String.prototype.reverse = function(){ > return this.split('').reverse().join('') > } > > It seems natural to have such method. Why not? > > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > <https://link.getmailspring.com/link/[email protected]/4?redirect=mailto%3Aes-discuss%40mozilla.org&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> > https://mail.mozilla.org/listinfo/es-discuss > <https://link.getmailspring.com/link/[email protected]/5?redirect=https%3A%2F%2Fmail.mozilla.org%2Flistinfo%2Fes-discuss&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> > > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > [image: Open Tracking] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180318/ed8aaa69/attachment-0001.html>
.reverse would only be reasonable for a subset of characters supported by Unicode. Its primary cited use case is for a particular educational example, when there are probably thousands of similar examples of educational snippets that would be rarely used in a production environment. Given that, it would be far better for those people who really need it to just provide that to their students as a provided function for the sake of that example.
Mark
.reverse would only be reasonable for a subset of characters supported by Unicode. Its primary cited use case is for a particular educational example, when there are probably thousands of similar examples of educational snippets that would be rarely used in a production environment. Given that, it would be far better for those people who really need it to just provide that to their students as a provided function for the sake of that example. Mark On Sun, Mar 18, 2018 at 8:56 AM, Grigory Hatsevich <g.hatsevich at gmail.com> wrote: > "This would remove the challenge and actively worsen their learning > process" -- this is not true. You can see it e.g. by looking at the > specific task I was talking about: > > "Given a string, find the shortest possible string which can be achieved > by adding characters to the end of initial string to make it a palindrome." > > This is my code for this task: > > function buildPalindrome(s){ > String.prototype.reverse=function(){ > return this.split('').reverse().join('') > } > > function isPalindrome(s){ > return s===s.reverse() > } > for (i=0;i<s.length;i++){ > first=s.slice(0,i); > rest=s.slice(i); > if(isPalindrome(rest)){ > return s+first.reverse() > } > } > } > > > As you see, the essence of this challenge is not in the process of > reversing a string. Having a reverse() method just makes the code more > readable -- comparing to alternative when one would have to write > .split('').reverse().join('') each time instead of just .reverse() > > On Sun, Mar 18, 2018 at 2:38 PM, Frederick Stark <coagmano at gmail.com> > wrote: > >> The point of a coding task for a beginner is to practice their problem >> solving skills to solve the task. This would remove the challenge and >> actively worsen their learning process >> >> >> On Mar 18 2018, at 6:26 pm, Grigory Hatsevich <g.hatsevich at gmail.com> >> wrote: >> >> >> My use case is solving coding tasks about palindromes on codefights.com. >> Not sure if that counts as "real-world", but probably a lot of beginning >> developers encounter such tasks at least once. >> >> >> >> >> On Sun, 18 Mar 2018 06:41:46 +0700, Mathias Bynens <mathias at qiwi.be> >> wrote: >> >> So far no one has provided a real-world use case. >> >> On Mar 18, 2018 10:15, "Mike Samuel" <mikesamuel at gmail.com >> <https://link.getmailspring.com/link/[email protected]/0?redirect=mailto%3Amikesamuel%40gmail.com&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> >> wrote: >> >> Previous discussion: https://esdiscuss.org/topic/wi >> ki-updates-for-string-number-and-math-libraries#content-1 >> <https://link.getmailspring.com/link/[email protected]/1?redirect=https%3A%2F%2Fesdiscuss.org%2Ftopic%2Fwiki-updates-for-string-number-and-math-libraries%23content-1&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >> >> """ >> String.prototype.reverse(), as proposed, corrupts supplementary >> characters. Clause 6 of Ecma-262 redefines the word "character" as "a >> 16-bit unsigned value used to represent a single 16-bit unit of text", that >> is, a UTF-16 code unit. In contrast, the phrase "Unicode character" is used >> for Unicode code points. For reverse(), this means that the proposed spec >> will reverse the sequence of the two UTF-16 code units representing a >> supplementary character, resulting in corruption. If this function is >> really needed (is it? for what?), it should preserve the order of surrogate >> pairs, as does java.lang.StringBuilder.reverse: >> download.oracle.com/javase/7/docs/api/java/lang/StringBui >> lder.html#reverse() >> <https://link.getmailspring.com/link/[email protected]/2?redirect=http%3A%2F%2Fdownload.oracle.com%2Fjavase%2F7%2Fdocs%2Fapi%2Fjava%2Flang%2FStringBuilder.html%23reverse()&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >> """ >> >> On Sat, Mar 17, 2018 at 1:41 PM, Grigory Hatsevich <g.hatsevich at gmail.com >> <https://link.getmailspring.com/link/[email protected]/3?redirect=mailto%3Ag.hatsevich%40gmail.com&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> >> wrote: >> >> Hi! I would propose to add reverse() method to strings. Something >> equivalent to the following: >> >> String.prototype.reverse = function(){ >> return this.split('').reverse().join('') >> } >> >> It seems natural to have such method. Why not? >> >> >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> <https://link.getmailspring.com/link/[email protected]/4?redirect=mailto%3Aes-discuss%40mozilla.org&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >> https://mail.mozilla.org/listinfo/es-discuss >> <https://link.getmailspring.com/link/[email protected]/5?redirect=https%3A%2F%2Fmail.mozilla.org%2Flistinfo%2Fes-discuss&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >> >> >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> [image: Open Tracking] > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180318/d81404bc/attachment-0001.html>
I have had to use that one, parsing texts and I remember I had to reverse strings that represented tokens...but that was very specific.
What I would like to see in strings would be something like "firstCase" for
transforming "felipe" into "Felipe" for example.
I always have to use something like str[0].toUpperCase() + str.slice(1)
.
The only reason I would defend the "reverse" method in strings is because it makes sense. I think JavaScript is very intuitive, and, as Arrays do have the "reverse" method, that simply makes sense to have it in strings as well.
Cheers.
[ ]s
--
Felipe N. Moura Web Developer, Google Developer Expert developers.google.com/experts/people/felipe-moura, Founder of
BrazilJS braziljs.org and Nasc nasc.io.
Website: felipenmoura.com / nasc.io Twitter: @felipenmoura twitter.com/felipenmoura
Facebook: fb.com/felipenmoura LinkedIn: goo.gl/qGmq
Changing the world is the least I expect from myself!
I have had to use that one, parsing texts and I remember I had to reverse strings that represented tokens...but that was very specific. What I would like to see in strings would be something like "firstCase" for transforming "felipe" into "Felipe" for example. I always have to use something like `str[0].toUpperCase() + str.slice(1)`. The only reason I would defend the "reverse" method in strings is because it makes sense. I think JavaScript is very intuitive, and, as Arrays do have the "reverse" method, that simply makes sense to have it in strings as well. Cheers. [ ]s *--* *Felipe N. Moura* Web Developer, Google Developer Expert <https://developers.google.com/experts/people/felipe-moura>, Founder of BrazilJS <https://braziljs.org/> and Nasc <http://nasc.io/>. Website: http://felipenmoura.com / http://nasc.io/ Twitter: @felipenmoura <http://twitter.com/felipenmoura> Facebook: http://fb.com/felipenmoura LinkedIn: http://goo.gl/qGmq --------------------------------- *Changing the world* is the least I expect from myself! On Sun, Mar 18, 2018 at 12:00 PM, Mark Davis ☕️ <mark at macchiato.com> wrote: > .reverse would only be reasonable for a subset of characters supported by > Unicode. Its primary cited use case is for a particular educational > example, when there are probably thousands of similar examples of educational > snippets that would be rarely used in a production environment. Given > that, it would be far better for those people who really need it to just > provide that to their students as a provided function for the sake of that > example. > > Mark > > On Sun, Mar 18, 2018 at 8:56 AM, Grigory Hatsevich <g.hatsevich at gmail.com> > wrote: > >> "This would remove the challenge and actively worsen their learning >> process" -- this is not true. You can see it e.g. by looking at the >> specific task I was talking about: >> >> "Given a string, find the shortest possible string which can be achieved >> by adding characters to the end of initial string to make it a palindrome." >> >> This is my code for this task: >> >> function buildPalindrome(s){ >> String.prototype.reverse=function(){ >> return this.split('').reverse().join('') >> } >> >> function isPalindrome(s){ >> return s===s.reverse() >> } >> for (i=0;i<s.length;i++){ >> first=s.slice(0,i); >> rest=s.slice(i); >> if(isPalindrome(rest)){ >> return s+first.reverse() >> } >> } >> } >> >> >> As you see, the essence of this challenge is not in the process of >> reversing a string. Having a reverse() method just makes the code more >> readable -- comparing to alternative when one would have to write >> .split('').reverse().join('') each time instead of just .reverse() >> >> On Sun, Mar 18, 2018 at 2:38 PM, Frederick Stark <coagmano at gmail.com> >> wrote: >> >>> The point of a coding task for a beginner is to practice their problem >>> solving skills to solve the task. This would remove the challenge and >>> actively worsen their learning process >>> >>> >>> On Mar 18 2018, at 6:26 pm, Grigory Hatsevich <g.hatsevich at gmail.com> >>> wrote: >>> >>> >>> My use case is solving coding tasks about palindromes on codefights.com. >>> Not sure if that counts as "real-world", but probably a lot of beginning >>> developers encounter such tasks at least once. >>> >>> >>> >>> >>> On Sun, 18 Mar 2018 06:41:46 +0700, Mathias Bynens <mathias at qiwi.be> >>> wrote: >>> >>> So far no one has provided a real-world use case. >>> >>> On Mar 18, 2018 10:15, "Mike Samuel" <mikesamuel at gmail.com >>> <https://link.getmailspring.com/link/[email protected]/0?redirect=mailto%3Amikesamuel%40gmail.com&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> >>> wrote: >>> >>> Previous discussion: https://esdiscuss.org/topic/wi >>> ki-updates-for-string-number-and-math-libraries#content-1 >>> <https://link.getmailspring.com/link/[email protected]/1?redirect=https%3A%2F%2Fesdiscuss.org%2Ftopic%2Fwiki-updates-for-string-number-and-math-libraries%23content-1&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >>> >>> """ >>> String.prototype.reverse(), as proposed, corrupts supplementary >>> characters. Clause 6 of Ecma-262 redefines the word "character" as "a >>> 16-bit unsigned value used to represent a single 16-bit unit of text", that >>> is, a UTF-16 code unit. In contrast, the phrase "Unicode character" is used >>> for Unicode code points. For reverse(), this means that the proposed spec >>> will reverse the sequence of the two UTF-16 code units representing a >>> supplementary character, resulting in corruption. If this function is >>> really needed (is it? for what?), it should preserve the order of surrogate >>> pairs, as does java.lang.StringBuilder.reverse: >>> download.oracle.com/javase/7/docs/api/java/lang/StringBuil >>> der.html#reverse() >>> <https://link.getmailspring.com/link/[email protected]/2?redirect=http%3A%2F%2Fdownload.oracle.com%2Fjavase%2F7%2Fdocs%2Fapi%2Fjava%2Flang%2FStringBuilder.html%23reverse()&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >>> """ >>> >>> On Sat, Mar 17, 2018 at 1:41 PM, Grigory Hatsevich < >>> g.hatsevich at gmail.com >>> <https://link.getmailspring.com/link/[email protected]/3?redirect=mailto%3Ag.hatsevich%40gmail.com&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> >>> wrote: >>> >>> Hi! I would propose to add reverse() method to strings. Something >>> equivalent to the following: >>> >>> String.prototype.reverse = function(){ >>> return this.split('').reverse().join('') >>> } >>> >>> It seems natural to have such method. Why not? >>> >>> >>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> <https://link.getmailspring.com/link/[email protected]/4?redirect=mailto%3Aes-discuss%40mozilla.org&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >>> https://mail.mozilla.org/listinfo/es-discuss >>> <https://link.getmailspring.com/link/[email protected]/5?redirect=https%3A%2F%2Fmail.mozilla.org%2Flistinfo%2Fes-discuss&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >>> >>> >>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> [image: Open Tracking] >> >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180318/7aadc60a/attachment.html>
For arrays, indexing is unambiguous: array[42]
is whatever value you put
there. As a result, it’s clear what it means to “reverse” an array.
This is not the case for strings, where indexing is inherently ambiguous.
Should string[42]
index by UCS-2/UTF-16 code unit? By Unicode code point?
By grapheme cluster?
For arrays, indexing is unambiguous: `array[42]` is whatever value you put there. As a result, it’s clear what it means to “reverse” an array. This is not the case for strings, where indexing is inherently ambiguous. Should `string[42]` index by UCS-2/UTF-16 code unit? By Unicode code point? By grapheme cluster? On Mon, Mar 19, 2018 at 6:28 AM, Felipe Nascimento de Moura < felipenmoura at gmail.com> wrote: > I have had to use that one, parsing texts and I remember I had to reverse > strings that represented tokens...but that was very specific. > > What I would like to see in strings would be something like "firstCase" > for transforming "felipe" into "Felipe" for example. > I always have to use something like `str[0].toUpperCase() + str.slice(1)`. > > The only reason I would defend the "reverse" method in strings is because > it makes sense. > I think JavaScript is very intuitive, and, as Arrays do have the "reverse" > method, that simply makes sense to have it in strings as well. > > Cheers. > > > [ ]s > > *--* > > *Felipe N. Moura* > Web Developer, Google Developer Expert > <https://developers.google.com/experts/people/felipe-moura>, Founder of > BrazilJS <https://braziljs.org/> and Nasc <http://nasc.io/>. > > Website: http://felipenmoura.com / http://nasc.io/ > Twitter: @felipenmoura <http://twitter.com/felipenmoura> > Facebook: http://fb.com/felipenmoura > LinkedIn: http://goo.gl/qGmq > --------------------------------- > *Changing the world* is the least I expect from myself! > > On Sun, Mar 18, 2018 at 12:00 PM, Mark Davis ☕️ <mark at macchiato.com> > wrote: > >> .reverse would only be reasonable for a subset of characters supported by >> Unicode. Its primary cited use case is for a particular educational >> example, when there are probably thousands of similar examples of educational >> snippets that would be rarely used in a production environment. Given >> that, it would be far better for those people who really need it to just >> provide that to their students as a provided function for the sake of that >> example. >> >> Mark >> >> On Sun, Mar 18, 2018 at 8:56 AM, Grigory Hatsevich <g.hatsevich at gmail.com >> > wrote: >> >>> "This would remove the challenge and actively worsen their learning >>> process" -- this is not true. You can see it e.g. by looking at the >>> specific task I was talking about: >>> >>> "Given a string, find the shortest possible string which can be achieved >>> by adding characters to the end of initial string to make it a palindrome." >>> >>> This is my code for this task: >>> >>> function buildPalindrome(s){ >>> String.prototype.reverse=function(){ >>> return this.split('').reverse().join('') >>> } >>> >>> function isPalindrome(s){ >>> return s===s.reverse() >>> } >>> for (i=0;i<s.length;i++){ >>> first=s.slice(0,i); >>> rest=s.slice(i); >>> if(isPalindrome(rest)){ >>> return s+first.reverse() >>> } >>> } >>> } >>> >>> >>> As you see, the essence of this challenge is not in the process of >>> reversing a string. Having a reverse() method just makes the code more >>> readable -- comparing to alternative when one would have to write >>> .split('').reverse().join('') each time instead of just .reverse() >>> >>> On Sun, Mar 18, 2018 at 2:38 PM, Frederick Stark <coagmano at gmail.com> >>> wrote: >>> >>>> The point of a coding task for a beginner is to practice their problem >>>> solving skills to solve the task. This would remove the challenge and >>>> actively worsen their learning process >>>> >>>> >>>> On Mar 18 2018, at 6:26 pm, Grigory Hatsevich <g.hatsevich at gmail.com> >>>> wrote: >>>> >>>> >>>> My use case is solving coding tasks about palindromes on codefights.com. >>>> Not sure if that counts as "real-world", but probably a lot of beginning >>>> developers encounter such tasks at least once. >>>> >>>> >>>> >>>> >>>> On Sun, 18 Mar 2018 06:41:46 +0700, Mathias Bynens <mathias at qiwi.be> >>>> wrote: >>>> >>>> So far no one has provided a real-world use case. >>>> >>>> On Mar 18, 2018 10:15, "Mike Samuel" <mikesamuel at gmail.com >>>> <https://link.getmailspring.com/link/[email protected]/0?redirect=mailto%3Amikesamuel%40gmail.com&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> >>>> wrote: >>>> >>>> Previous discussion: https://esdiscuss.org/topic/wi >>>> ki-updates-for-string-number-and-math-libraries#content-1 >>>> <https://link.getmailspring.com/link/[email protected]/1?redirect=https%3A%2F%2Fesdiscuss.org%2Ftopic%2Fwiki-updates-for-string-number-and-math-libraries%23content-1&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >>>> >>>> """ >>>> String.prototype.reverse(), as proposed, corrupts supplementary >>>> characters. Clause 6 of Ecma-262 redefines the word "character" as "a >>>> 16-bit unsigned value used to represent a single 16-bit unit of text", that >>>> is, a UTF-16 code unit. In contrast, the phrase "Unicode character" is used >>>> for Unicode code points. For reverse(), this means that the proposed spec >>>> will reverse the sequence of the two UTF-16 code units representing a >>>> supplementary character, resulting in corruption. If this function is >>>> really needed (is it? for what?), it should preserve the order of surrogate >>>> pairs, as does java.lang.StringBuilder.reverse: >>>> download.oracle.com/javase/7/docs/api/java/lang/StringBuil >>>> der.html#reverse() >>>> <https://link.getmailspring.com/link/[email protected]/2?redirect=http%3A%2F%2Fdownload.oracle.com%2Fjavase%2F7%2Fdocs%2Fapi%2Fjava%2Flang%2FStringBuilder.html%23reverse()&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >>>> """ >>>> >>>> On Sat, Mar 17, 2018 at 1:41 PM, Grigory Hatsevich < >>>> g.hatsevich at gmail.com >>>> <https://link.getmailspring.com/link/[email protected]/3?redirect=mailto%3Ag.hatsevich%40gmail.com&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> >>>> wrote: >>>> >>>> Hi! I would propose to add reverse() method to strings. Something >>>> equivalent to the following: >>>> >>>> String.prototype.reverse = function(){ >>>> return this.split('').reverse().join('') >>>> } >>>> >>>> It seems natural to have such method. Why not? >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> <https://link.getmailspring.com/link/[email protected]/4?redirect=mailto%3Aes-discuss%40mozilla.org&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> <https://link.getmailspring.com/link/[email protected]/5?redirect=https%3A%2F%2Fmail.mozilla.org%2Flistinfo%2Fes-discuss&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> [image: Open Tracking] >>> >>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180319/bd8accea/attachment-0001.html>
If more than one type of reversal makes sense, are there any good reasons
against covering this by an optional mode
argument? This approach would be
analogous to String.prototype.normalize
.
If more than one type of reversal makes sense, are there any good reasons against covering this by an optional `mode` argument? This approach would be analogous to `String.prototype.normalize`. On Sunday, March 18, 2018 9:38:18 PM CET Mathias Bynens wrote: > For arrays, indexing is unambiguous: `array[42]` is whatever value you put > there. As a result, it’s clear what it means to “reverse” an array. > > This is not the case for strings, where indexing is inherently ambiguous. > Should `string[42]` index by UCS-2/UTF-16 code unit? By Unicode code point? > By grapheme cluster? > > > > On Mon, Mar 19, 2018 at 6:28 AM, Felipe Nascimento de Moura < > > felipenmoura at gmail.com> wrote: > > I have had to use that one, parsing texts and I remember I had to reverse > > strings that represented tokens...but that was very specific. > > > > What I would like to see in strings would be something like "firstCase" > > for transforming "felipe" into "Felipe" for example. > > I always have to use something like `str[0].toUpperCase() + str.slice(1)`. > > > > The only reason I would defend the "reverse" method in strings is because > > it makes sense. > > I think JavaScript is very intuitive, and, as Arrays do have the "reverse" > > method, that simply makes sense to have it in strings as well. > > > > Cheers. > > > > > > [ ]s > > > > *--* > > > > *Felipe N. Moura* > > Web Developer, Google Developer Expert > > <https://developers.google.com/experts/people/felipe-moura>, Founder of > > BrazilJS <https://braziljs.org/> and Nasc <http://nasc.io/>. > > > > Website: http://felipenmoura.com / http://nasc.io/ > > Twitter: @felipenmoura <http://twitter.com/felipenmoura> > > Facebook: http://fb.com/felipenmoura > > LinkedIn: http://goo.gl/qGmq > > --------------------------------- > > *Changing the world* is the least I expect from myself! > > > > On Sun, Mar 18, 2018 at 12:00 PM, Mark Davis ☕️ <mark at macchiato.com> > > > > wrote: > >> .reverse would only be reasonable for a subset of characters supported by > >> Unicode. Its primary cited use case is for a particular educational > >> example, when there are probably thousands of similar examples of > >> educational snippets that would be rarely used in a production > >> environment. Given that, it would be far better for those people who > >> really need it to just provide that to their students as a provided > >> function for the sake of that example. > >> > >> Mark > >> > >> On Sun, Mar 18, 2018 at 8:56 AM, Grigory Hatsevich <g.hatsevich at gmail.com > >> > >> > wrote: > >>> "This would remove the challenge and actively worsen their learning > >>> process" -- this is not true. You can see it e.g. by looking at the > >>> specific task I was talking about: > >>> > >>> "Given a string, find the shortest possible string which can be achieved > >>> by adding characters to the end of initial string to make it a > >>> palindrome." > >>> > >>> This is my code for this task: > >>> > >>> function buildPalindrome(s){ > >>> > >>> String.prototype.reverse=function(){ > >>> > >>> return this.split('').reverse().join('') > >>> > >>> } > >>> > >>> function isPalindrome(s){ > >>> > >>> return s===s.reverse() > >>> > >>> } > >>> for (i=0;i<s.length;i++){ > >>> > >>> first=s.slice(0,i); > >>> rest=s.slice(i); > >>> if(isPalindrome(rest)){ > >>> > >>> return s+first.reverse() > >>> > >>> } > >>> > >>> } > >>> > >>> } > >>> > >>> > >>> As you see, the essence of this challenge is not in the process of > >>> reversing a string. Having a reverse() method just makes the code more > >>> readable -- comparing to alternative when one would have to write > >>> .split('').reverse().join('') each time instead of just .reverse() > >>> > >>> On Sun, Mar 18, 2018 at 2:38 PM, Frederick Stark <coagmano at gmail.com> > >>> > >>> wrote: > >>>> The point of a coding task for a beginner is to practice their problem > >>>> solving skills to solve the task. This would remove the challenge and > >>>> actively worsen their learning process > >>>> > >>>> > >>>> On Mar 18 2018, at 6:26 pm, Grigory Hatsevich <g.hatsevich at gmail.com> > >>>> wrote: > >>>> > >>>> > >>>> My use case is solving coding tasks about palindromes on > >>>> codefights.com. > >>>> Not sure if that counts as "real-world", but probably a lot of > >>>> beginning > >>>> developers encounter such tasks at least once. > >>>> > >>>> > >>>> > >>>> > >>>> On Sun, 18 Mar 2018 06:41:46 +0700, Mathias Bynens <mathias at qiwi.be> > >>>> wrote: > >>>> > >>>> So far no one has provided a real-world use case. > >>>> > >>>> On Mar 18, 2018 10:15, "Mike Samuel" <mikesamuel at gmail.com > >>>> <https://link.getmailspring.com/link/1521358598.local-593d9031-9a3d-v1. > >>>> 1.5-5834c99f at getmailspring.com/0?redirect=mailto%3Amikesamuel%40gmail.c > >>>> om&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> wrote: > >>>> > >>>> Previous discussion: https://esdiscuss.org/topic/wi > >>>> ki-updates-for-string-number-and-math-libraries#content-1 > >>>> <https://link.getmailspring.com/link/1521358598.local-593d9031-9a3d-v1. > >>>> 1.5-5834c99f at getmailspring.com/1?redirect=https%3A%2F%2Fesdiscuss.org%2 > >>>> Ftopic%2Fwiki-updates-for-string-number-and-math-libraries%23content-1& > >>>> recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> > >>>> > >>>> """ > >>>> String.prototype.reverse(), as proposed, corrupts supplementary > >>>> characters. Clause 6 of Ecma-262 redefines the word "character" as "a > >>>> 16-bit unsigned value used to represent a single 16-bit unit of text", > >>>> that > >>>> is, a UTF-16 code unit. In contrast, the phrase "Unicode character" is > >>>> used > >>>> for Unicode code points. For reverse(), this means that the proposed > >>>> spec > >>>> will reverse the sequence of the two UTF-16 code units representing a > >>>> supplementary character, resulting in corruption. If this function is > >>>> really needed (is it? for what?), it should preserve the order of > >>>> surrogate > >>>> pairs, as does java.lang.StringBuilder.reverse: > >>>> download.oracle.com/javase/7/docs/api/java/lang/StringBuil > >>>> der.html#reverse() > >>>> <https://link.getmailspring.com/link/1521358598.local-593d9031-9a3d-v1. > >>>> 1.5-5834c99f at getmailspring.com/2?redirect=http%3A%2F%2Fdownload.oracle. > >>>> com%2Fjavase%2F7%2Fdocs%2Fapi%2Fjava%2Flang%2FStringBuilder.html%23reve > >>>> rse()&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> """ > >>>> > >>>> On Sat, Mar 17, 2018 at 1:41 PM, Grigory Hatsevich < > >>>> g.hatsevich at gmail.com > >>>> <https://link.getmailspring.com/link/1521358598.local-593d9031-9a3d-v1. > >>>> 1.5-5834c99f at getmailspring.com/3?redirect=mailto%3Ag.hatsevich%40gmail. > >>>> com&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t>> wrote: > >>>> > >>>> Hi! I would propose to add reverse() method to strings. Something > >>>> equivalent to the following: > >>>> > >>>> String.prototype.reverse = function(){ > >>>> > >>>> return this.split('').reverse().join('') > >>>> > >>>> } > >>>> > >>>> It seems natural to have such method. Why not? > >>>> > >>>> > >>>> > >>>> > >>>> _______________________________________________ > >>>> es-discuss mailing list > >>>> es-discuss at mozilla.org > >>>> <https://link.getmailspring.com/link/1521358598.local-593d9031-9a3d-v1. > >>>> 1.5-5834c99f at getmailspring.com/4?redirect=mailto%3Aes-discuss%40mozilla > >>>> .org&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> > >>>> https://mail.mozilla.org/listinfo/es-discuss > >>>> <https://link.getmailspring.com/link/1521358598.local-593d9031-9a3d-v1. > >>>> 1.5-5834c99f at getmailspring.com/5?redirect=https%3A%2F%2Fmail.mozilla.or > >>>> g%2Flistinfo%2Fes-discuss&recipient=Zy5oYXRzZXZpY2hAZ21haWwuY29t> > >>>> > >>>> > >>>> > >>>> > >>>> _______________________________________________ > >>>> es-discuss mailing list > >>>> es-discuss at mozilla.org > >>>> https://mail.mozilla.org/listinfo/es-discuss > >>>> > >>>> [image: Open Tracking] > >>> > >>> _______________________________________________ > >>> es-discuss mailing list > >>> es-discuss at mozilla.org > >>> https://mail.mozilla.org/listinfo/es-discuss > >> > >> _______________________________________________ > >> es-discuss mailing list > >> es-discuss at mozilla.org > >> https://mail.mozilla.org/listinfo/es-discuss > > > > _______________________________________________ > > es-discuss mailing list > > es-discuss at mozilla.org > > https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part. URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180318/0ab38a4b/attachment.sig>
The only reason I would defend the "reverse" method in strings is because it makes sense. I think JavaScript is very intuitive, and, as Arrays do have the "reverse" method, that simply makes sense to have it in strings as well.
”Making sense” and ”symmetry of API” is not a sufficient reason, because a string is not ”just” an immutable array of chars. Consider:
- Some methods defined on arrays only:
find
,reduce
,reverse
- Some methods defined on strings only:
repeat
,startsWith
- Some methods defined on both arrays and strings with same semantics:
concat
,slice
- Some methods defined on both arrays and strings with different semantics:
includes
,indexOf
Existence of methods listed in (1), (2) and (4) is a consequence of strings and arrays having different needs.
> > The only reason I would defend the "reverse" method in strings is because it makes sense. > I think JavaScript is very intuitive, and, as Arrays do have the "reverse" method, that simply makes sense to have it in strings as well. > ”Making sense” and ”symmetry of API” is not a sufficient reason, because a string is not ”just” an immutable array of chars. Consider: 1. Some methods defined on arrays only: `find`, `reduce`, `reverse` 2. Some methods defined on strings only: `repeat`, `startsWith` 3. Some methods defined on both arrays and strings with same semantics: `concat`, `slice` 4. Some methods defined on both arrays and strings with different semantics: `includes`, `indexOf` Existence of methods listed in (1), (2) and (4) is a consequence of strings and arrays having different needs. —Claude
yep agreed...that's not enough reason (I just added that might be "the reason for...").
Cheers.
[ ]s
--
Felipe N. Moura Web Developer, Google Developer Expert developers.google.com/experts/people/felipe-moura, Founder of
BrazilJS braziljs.org and Nasc nasc.io.
Website: felipenmoura.com / nasc.io Twitter: @felipenmoura twitter.com/felipenmoura
Facebook: fb.com/felipenmoura LinkedIn: goo.gl/qGmq
Changing the world is the least I expect from myself!
yep agreed...that's not enough reason (I just added that might be "the reason for..."). Cheers. [ ]s *--* *Felipe N. Moura* Web Developer, Google Developer Expert <https://developers.google.com/experts/people/felipe-moura>, Founder of BrazilJS <https://braziljs.org/> and Nasc <http://nasc.io/>. Website: http://felipenmoura.com / http://nasc.io/ Twitter: @felipenmoura <http://twitter.com/felipenmoura> Facebook: http://fb.com/felipenmoura LinkedIn: http://goo.gl/qGmq --------------------------------- *Changing the world* is the least I expect from myself! On Mon, Mar 19, 2018 at 5:38 AM, Claude Pache <claude.pache at gmail.com> wrote: > > > > > > The only reason I would defend the "reverse" method in strings is > because it makes sense. > > I think JavaScript is very intuitive, and, as Arrays do have the > "reverse" method, that simply makes sense to have it in strings as well. > > > > ”Making sense” and ”symmetry of API” is not a sufficient reason, because a > string is not ”just” an immutable array of chars. Consider: > > 1. Some methods defined on arrays only: `find`, `reduce`, `reverse` > 2. Some methods defined on strings only: `repeat`, `startsWith` > 3. Some methods defined on both arrays and strings with same semantics: > `concat`, `slice` > 4. Some methods defined on both arrays and strings with different > semantics: `includes`, `indexOf` > > Existence of methods listed in (1), (2) and (4) is a consequence of > strings and arrays having different needs. > > —Claude > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180319/78cb4dbe/attachment.html>
I would propose to add reverse() method to strings. Something equivalent to the following:
String.prototype.reverse = function(){ return this.split('').reverse().join('') }
It seems natural to have such method. Why not?