12 Nov 2022
•
kata
Through the last few years, I’ve mentored a few folks at Exercism.
Once thing tickles me everytime is how we (as individual) tends to write software.
Often, imperative approach is used to describe what we want to achieve. It’s not a bad thing, not at all. You sometimes need to be imperative.
Nevertheless, as a software engineer, I like to use declarative approach. Since we’re writing code for people and not machine. I think it’s the best I can do to communicate my intent the better way.
More …
09 Oct 2022
•
discussion
In my spare time, I like to mentor on the Exercism platform.
I do Elixir, Swift and a bit of Erlang, even if the latest is not a language I do quite often.
The Ruby syllabus is good, it covers 16 topics, from Strings to Enumeration and Ostruct.
I’d like to emphasize one exercise I’ve gone through and show how we can go from a one liner to a more production ready code.
The main goal is to show that, yes oneliners are cool and you can brag… but no one cares. Production code is the goto whenever you’re trying to solve a kata or whatever.
The gist
Given a number, find the sum of all the unique multiples of particular numbers up to but not including that number.
If we list all the natural numbers below 20 that are multiples of 3 or 5, we get 3, 5, 6, 9, 10, 12, 15, and 18.
The sum of these multiples is 78.
And here you can find my very first shot.
class SumOfMultiples
def initialize(*multiples)
@multiples = multiples
end
def to(limit)
return 0 if @multiples.include?(0)
(0...limit).filter { |integer| @multiples.any? { |multiple| integer.remainder(multiple).zero? } }.sum
end
end
It is quite simple, we make an early return if multiples contains 0.
Then we filter on the range from 0 to the limit, we use the block to look for a factor, the we filter and then we sum this up.
More …
07 Jan 2022
•
kata
I’ve lately decided to make some katas again.
Still on codewars’ 5kyu tier, I’ve tackled the rot13 exercice.
What’s the gist of this one?
ROT13 is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is an example of the Caesar cipher.
Create a function that takes a string and returns the string ciphered with Rot13. If there are numbers or special characters included in the string, they should be returned as they are. Only letters from the latin/english alphabet should be shifted, like in the original Rot13 “implementation”.
We’ll need to handle strings, nice.
Based on the description, test should output grfg.
More …
07 Jan 2022
•
kata
As I did the rot13 in Elixir, trying to achieve it in Ruby would be fun too.
So in Ruby, you can get the codepoints of a String using String#each_codepoint and then call to_a like this.
"abc".each_codepoint.to_a # => [97, 98, 99]
Fortunately, Ruby provides a shorthand way of doing this: String#codepoints.
More …
28 Dec 2021
•
technical
On a daily basis at work I use 2 languages. Java and Javascript.
Doing Javascript everyday and learning Elixir, I recognize some patterns. Let’s recap.
Nobody ignores in the web dev planet the features that ES6 ships to the Javascript language, especially the functional ones.
Summary
- Objects vs Modules
- Method chaining vs Pipe Operator
- Destructuring vs Pattern Matching
- High Order Functions
More …