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 noop = () => {} | |
| function formatProductForRequest(product) { | |
| // ... | |
| } | |
| export function addToCart(product, onSuccess = noop, onFailure = noop) { | |
| return (dispatch, getState) => { | |
| dispatch(cartAddAttempt(()) |
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 { addToCart } from "shared/lib/actions" | |
| class ProductContainer extends React.Component { | |
| // ... | |
| addToCart(product) { | |
| const { dispatch, navigator } = this.props | |
| return dispatch(addToCart(product, () => { | |
| const route = Router.getCartRoute() |
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
| HappyNumberFinder.find(400) #=> ???? |
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
| HappyNumberFinder.find(49) #=> {:happy} |
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
| IO.puts(“The number is #{number}”) |
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
| HappyNumberFinder.find(49) #=> {:happy} | |
| HappyNumberFinder.find(324) #=> {:unhappy} |
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 HappyNumberFinder do | |
| def find(number) when number > 0 do | |
| _find(number, []) | |
| end | |
| defp get_sum(number) do | |
| number | |
| |> Integer.digits | |
| |> Enum.map(fn(x) -> x * x end) |
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 HappyNumberFinder do | |
| # def get_sum(number) | |
| def find(number) do | |
| _find(number, []) | |
| end | |
| defp _find(number, guesses) where number in guesses do | |
| {:unhappy} |
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 HappyNumberFinder do | |
| # def get_sum(number) | |
| def find(number) do | |
| _find(number, []) | |
| end | |
| defp _find(number, guesses) do | |
| sum = get_sum(number) |
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 HappyNumberFinder do | |
| # def get_sum(number) | |
| def find(number) do | |
| sum = get_sum(number) | |
| case sum do | |
| 1 -> {:happy} | |
| _ -> find(sum) |