JS Built-ins
StringString.prototype.atintermediate

String.prototype.at() β€” middle character

πŸ“– Usage Example
const str = 'Hello'
str.at(0)    // β†’ 'H'
str.at(-1)   // β†’ 'o'
str.at(1)    // β†’ 'e'

Use at() to access a character by index, supporting negative indices to count from the end.

String.prototype.at() β€” Middle Index

Challenge: Implement middleChar(str) that returns the middle character of an odd-length string using .at().

middleChar('hello') // β†’ 'l'
middleChar('abc')   // β†’ 'b'
πŸ’‘ Hints (1)
  • β€’ For a string of length `n`, the middle index is `Math.floor(n / 2)`.