Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

David kim #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

David kim #21

wants to merge 3 commits into from

Conversation

dyunkim
Copy link

@dyunkim dyunkim commented Sep 19, 2016

David Kim
40059634

@@ -36,7 +36,7 @@ defmodule Ex01 do
# Write a function that adds two numbers using fn syntax #
##########################################################

sum2a = your_anonymous_function(1, 2)
sum2a = fn(num1, num2) -> num1 + num2 end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

@@ -47,7 +47,7 @@ defmodule Ex01 do
# Write a function that adds two numbers using & syntax #
##########################################################

sum2b = your_anonymous_function(1, 2)
sum2b = &(&1 + &2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

@@ -60,7 +60,7 @@ defmodule Ex01 do
# no explicit + operators in your function #
#####################################################################

sum3a = your_anonymous_function(1, 2, 3)
sum3a = fn(num1, num2, num3) -> sum2b.(num1, sum2b.(num2, num3)) end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

@@ -71,7 +71,7 @@ defmodule Ex01 do
# Do the same using the & notation #
####################################

sum3b = your_anonymous_function
sum3b = &(sum2b.(&1, sum2b.(&2, &3)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

@@ -86,7 +86,9 @@ defmodule Ex01 do
# function. The examples below will make this clearer :) #
########################################################################

create_adder = your_anonymous_function(1)
create_adder = fn(add_num) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10

#
# end
# end
def list_equal(list1, list2) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0

Even if you were allowed to use Enum.at, it is generally a smell to use it with lists.

@@ -149,7 +174,27 @@ defmodule Ex03 do
Think a little about a nice way to lay this code out.
"""

def won . . . "your code"
def won(moves) do
Copy link
Contributor

@pragdave pragdave Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3

This is really procedural code. think how it might look with pattern matching:

  def won(position) do
    case position do
      { a, a, a,
        _, _, _,
        _, _, _ } -> a

      { _, _, _,
        a, a, a,
        _, _, _ } -> a

      { _, _, _,
        _, _, _,
        a, a, a } -> a

      { a, _, _,
        a, _, _,
        a, _, _ } -> a

      { _, a, _,
        _, a, _,
        _, a, _ } -> a

      { _, _, a,
        _, _, a,
        _, _, a } -> a

      { a, _, _,
        _, a, _,
        _, _, a } -> a

      { _, _, a,
        _, a, _,
        a, _, _ } -> a

      _ -> false
    end

return value will be the thing you have to manipulate.
"""

def even_odd(list) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

Several things hurt your mark here.

First, the partitioning is crying out to be in a new function. Second, you're using elem and list concatenation rather that pattern matching.

Here's an alternative;

  def even_odd(list) do
    reduce(list, { [], [] }, &assign_one_even_odd/2)
    |> reverse_two_lists
  end

  defp assign_one_even_odd(number, { evens, odds }) do
    cond do
      Integer.is_even(number)->
        { [ number | evens ], odds }
      Integer.is_odd(number) ->
        { evens, [ number | odds ] }
    end
  end

  defp reverse_two_lists({ evens, odds }) do
    { reverse(evens), reverse(odds) }
  end


def even_odd . . . "your code"
def min(list) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

-7

"""
def reverse(list) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants