Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
[]
is a more primitive way of accessing all kind of arrays.charAt()
is specific to strings.You can access the index of any array by using
[]
, but you can only usecharAt()
on a string.But when it comes to string alone, both are one and the same.
But you should use
charAt()
because, it is well supported in all the major browsers, while the bracket notation will returnundefined
in IE7Also, the bracket notation is simply accessed, while
charAt()
does some validation and doesn't returnundefined
, but will return an empty string""
Sources:
https://stackoverflow.com/a/22728925
https://stackoverflow.com/a/5943760
https://blog.vjeux.com/2009/javascript/dangerous-bracket-notation-for-strings.html
https://stackoverflow.com/a/5943807
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#character_access
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
it's not a completely ridiculous solution though.
What is your point exactly, did the chicken lay an egg or the egg produce a chicken?
I asked chatGPT to solve this kata, and this function with regular expression is the answer.