====== 2021-06-15 Entry ====== ===== Heap ===== [[https://en.wikipedia.org/wiki/IIf| 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. [[https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#and| 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 [[https://streamofcoding.com/ruby-double-ampersand-or-and/| More explanation of the and vs &&]] [[https://www.techotopia.com/index.php/Ruby_Operator_Precedence| Ruby precedence list]] [[https://chrisarcand.com/null-coalescing-operators-and-rubys-conditional-assignments/| Cull Coalescing Operators in Ruby]] [[https://en.wikipedia.org/wiki/Null_coalescing_operator| Wiki - Null Coalescing Operators]] [[https://en.wikipedia.org/wiki/Memoization| Wiki - Memoization]]