Redundant if/else - identity
def can_edit?
if admin?
true
else
false
end
end
#!/bin/sh | |
set -e | |
echo "== BUILDING THE APP ==" | |
yarn parcel build src/index.html | |
echo "== CONFIGURING REDIRECTS ==" | |
if [ "$CONTEXT" = "production" ]; then | |
cp production_redirects dist/_redirects |
Redundant if/else - identity
def can_edit?
if admin?
true
else
false
end
end
puts "4 line REPL (read eval print loop)" | |
$stdin.each_line do |line| # READ | |
return_value = eval(line.chomp) # EVAL | |
puts return_value # PRINT | |
end # LOOP |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ div [ class "icon" ] [ span [class "icon-profile" ] [] ] | |
, div [ class "icon" ] [ span [ class "icon-clock" ] [] ] | |
] | |
-- REFACTOR TO | |
view : Model -> Html Msg |
class NonEmptyArray | |
include Enumerable | |
def initialize(first, rest) | |
@first = first | |
@rest = rest | |
end | |
def first | |
@first |
def add(number1, number2) | |
number2.times.reduce(number1) { |total| total.next } | |
end | |
add(2,3) | |
# => 5 | |
def subtract(number1, number2) | |
number2.times.reduce(number1) { |total| total.pred } | |
end |
class Hamming | |
def self.zip_count(s1, s2) | |
s1.chars. | |
zip(s2.chars). | |
count { |c1, c2| c1 != c2 } | |
end | |
def self.for_loop(s1, s2) | |
distance = 0 |
class Hamming | |
def self.eager(s1, s2) | |
s1.chars. | |
zip(s2.chars). | |
count { |c1, c2| c1 != c2 } | |
end | |
def self.half_lazy(s1, s2) | |
s1.each_char. | |
zip(s2.each_char). |
class Hamming | |
def self.eager(s1, s2) | |
s1.chars.take(10). | |
zip(s2.chars.take(10)). | |
count { |c1, c2| c1 != c2 } | |
end | |
def self.half_lazy_args(s1, s2) | |
s1.each_char.take(10). | |
zip(s2.each_char.take(10)). |