daily:2021-06-16
This is an old revision of the document!
2021-06-15 Entry
Heap
IIf - Immediate If is a function used in visual basic that give a similar functionality to a ternary operator, however it has the fault of side effects where each expression will be ran and the return is decided by the testing expression.
Ruby `and` operator - low presedence can be made use of in a one line if statement to both set a value and break or next a loop. e.g.
def check_pegs(guesses, secrets)
hints = Array.new(4)
guesses.each_with_index do | g, i |
hints[i] = 'B' and next if g == secrets[i]
secrets.each_with_index do | s, j |
hints[j] = 'W' and break if g == s && hints[j].nil?
end
end
peg_count(hints)
end
However this can be confusing as a standard
&&
operator would set the value then next/break only if the statement after the if was
daily/2021-06-16.1623872329.txt.gz · Last modified: 2021/06/16 19:38 by chrisbolas
