DEV Community

Discussion on: JavaScript Katas: Position in Alphabet

Collapse
 
kosich profile image
Kostia Palchyk

Nice!

(Btw, you can use .indexOf on strings too)

My weird takes:

A regex approach

const positionInAlphabet = c => 'abcdefghijklmnopqrstuvwxyz'
  .replace(new RegExp(c + '.*', 'i') , c).length

Parsing with alphabet radix (26 + 10 for 0-9 numbers)

const positionInAlphabet = c => Number.parseInt(c, 36) - 9

Michael, make em a bit harder, please, to leave us some space for creativity :)

Collapse
 
miku86 profile image
miku86

Hey Kostia,

nice solution!

I probably wouldn't ever use my array solution,
because the prettier formatting would blocked the whole screen vertically haha.