This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Greeting do | |
| def hey(name) do | |
| name = name || "Tom" | |
| IO.puts "Hey, " <> name | |
| end | |
| end | |
| test_name = nil | |
| Greeting.hey(test_name) # Hello, Tom | |
| test_name # nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const hey = (person) => { | |
| person.name = person.name || "Tom"; | |
| console.log(`Hey, ${person.name}`); | |
| }; | |
| let bob = {}; | |
| hey(bob); // "Hey, Tom" | |
| bob // { name: "Tom" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # is it assignment? | |
| all_systems = :go | |
| # not quite | |
| :go = all_systems | |
| # alas age is but a number | |
| tom = %{name: "Tom", age: 25} | |
| %{age: num} = tom # 25 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Enum.join(Enum.reverse(String.split(String.upcase("war"), "")), "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "war" |> String.upcase |> String.split("") |> Enum.reverse |> Enum.join("") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "war" | |
| |> String.upcase | |
| |> String.split("") | |
| |> Enum.reverse | |
| |> Enum.join("") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "war".toUpperCase().split("").reverse().join(""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static TemporalAdjuster LAST_WORKING_DAY = TemporalAdjusters.ofDateAdjuster(lastDayOfMonth -> { | |
| int daysToSubtract = Math.max(0, lastDayOfMonth.getDayOfWeek().getValue() - DayOfWeek.FRIDAY.getValue()); | |
| return lastDayOfMonth.minusDays(daysToSubtract); | |
| }); | |
| // Example Usage | |
| LocalDate.now().with(LAST_WORKING_DAY); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.stream.*; | |
| import java.util.Arrays; | |
| // O(n) solution to the Trapped Water Problem | |
| // @see https://techdevguide.withgoogle.com/paths/advanced/volume-of-water/ | |
| public class TrappedWater { | |
| public static void main(String args[]) { | |
| int[] sampleTopography = { 1,3,2,4,1,3,1,4,5,2,2,1,4,2,2 }; | |
| int trappedWaterVolume = getTrappedWater(sampleTopography); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.stream.IntStream; | |
| import java.util.Arrays; | |
| // O(n^2) solution to the Trapped Water Problem | |
| // @see https://techdevguide.withgoogle.com/paths/advanced/volume-of-water/ | |
| public class TrappedWater { | |
| public static void main(String args[]) { | |
| int[] sampleTopography = { 1,3,2,4,1,3,1,4,5,2,2,1,4,2,2 }; | |
| int trappedWaterVolume = getTrappedWater(sampleTopography); |