User Tools

Site Tools


daily:2021-06-16

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
daily:2021-06-16 [2021/06/16 19:12] – created chrisbolasdaily:2021-06-16 [2021/06/16 21:13] (current) – [Heap] chrisbolas
Line 3: Line 3:
 ===== Heap ===== ===== 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.
 +<code>
 +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
 +</code>
 +
 +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]]
daily/2021-06-16.1623870722.txt.gz · Last modified: 2021/06/16 19:12 by chrisbolas