I'm a Software Engineer and a teacher.
There's no feeling quite like the one you get when you watch someone's eyes light up learning something they didn't know.
I'm a Software Engineer and a teacher.
There's no feeling quite like the one you get when you watch someone's eyes light up learning something they didn't know.
Well, my first attempt had me iterating calling .index on ("a".."z") only to find out that you can't call index on a range, so in trying to work around that I realized I could just convert the range into an array... :)
I forgot String are a table of Character so you right compactMap is useless.
I have totally ignored emojis because the challenger treat only letter a to z
So thank you for your feedback, your optimisation is truly better 👌
Second year Computer Science student with an interest in web/mobile development, big data, robotics and cyber security. Probably drinking too much coffee or coding to avoid doing other coding...
A bit like @nicolas Hervé, using the
reducemethod:[...a]transforms the string to an array with every character (["l", "o", "v", "e"])reducemethods will loop through every character, get its charCode, subtract96to it (the charCode associated with"a"+ 1), and sum everythingThanks to @ynndvn for showing me
reducemethod, it exist too in Swift language and it's awesome !!!This is my solution in Swift :
I started picking up ruby for rails, so here is my shining gem.
Try it out here
word.rb
word_test.rb
("a".."z").to_a is nifty!
Well, my first attempt had me iterating calling
.indexon("a".."z")only to find out that you can't call index on a range, so in trying to work around that I realized I could just convert the range into an array... :)Oh nice! That's better !
I forgot
Stringare a table ofCharacterso you rightcompactMapis useless.I have totally ignored emojis because the challenger treat only letter
atozSo thank you for your feedback, your optimisation is truly better 👌
A little solution for Ruby :) this was fun!
Here is the simple solution with Python:
In PHP
EDIT:
Haskell
Playground
Here.
My solution to the challenge using map and reduce in Python. If anyone has any suggestions on how to improve it, I would love to hear! :)
Here is my fun solution using Kotlin:
c#, one liner using linq, ignoring non-letters chars:
My Python Algorithm:
Ah okay gotcha, thank ya for the tip!
Thanks for your insight. I didn't know about subtract and when the second solution is kind of obscure to me it seems very cool and short.