If a = 1, b = 2, c = 3 ... z = 26
Then l + o + v + e = 54
and f + r + i + e + n + d + s + h + i + p = 108
So friendship is twice as strong as love :-)
Write a function to find the "strength" of each of these values.
Test cases:
wordsToMarks(attitude)
wordsToMarks(friends)
wordsToMarks(family)
wordsToMarks(selflessness)
wordsToMarks(knowledge)
Good luck!
This challenge comes from J or nor J on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (20)
Here is the simple solution with Python:
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! :)
In PHP
EDIT:
A little solution for Ruby :) this was fun!
Here is my fun solution using Kotlin:
Oh nice! That's better !
I forgot
String
are a table ofCharacter
so you rightcompactMap
is useless.I have totally ignored emojis because the challenger treat only letter
a
toz
So thank you for your feedback, your optimisation is truly better 👌
Ah okay gotcha, thank ya for the tip!
My Python Algorithm:
c#, one liner using linq, ignoring non-letters chars:
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.
Haskell
Playground
Here.
Thanks to @ynndvn for showing me
reduce
method, 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