Skip to content

Commit

Permalink
added Array#-
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed May 5, 2012
1 parent 86af16a commit 4f14ba1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/array.fy
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,32 @@ class Array {
arr
}

def + other_arr {
def + other {
"""
@return Concatenation of @self with another @Array@
@other @Fancy::Enumerable@ to be appended.
@return Concatenation of @self with @other.
Returns concatenation with another @Array@.
Returns concatenation with another @Fancy::Enumerable@.
Example:
[1,2,3] + [3,4,5] # => [1,2,3,3,4,5]
"""

clone append: other_arr
clone append: other
}

def - other {
"""
@other @Fancy::Enumerable@ to be subtracted from @self.
@return @Array@ of elements in @self excluding all elements in @self and @other.
Returns an @Array@ of all values in @self that are not in @other.
Example:
[1,2,3,4] - [2,4,5] # => [1,3]
"""

self reject: |x| { other includes?: x }
}

def indices {
Expand Down
8 changes: 8 additions & 0 deletions tests/array.fy
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ FancySpec describe: Array with: {
([1,2,3,4] + [-1,-2,-3,-4]) is: [1,2,3,4,-1,-2,-3,-4]
}

it: "returns all elements not in another collection" with: '- when: {
[] - [] is: []
[] - [0] is: []
[1,2,3,4] - [2,4] is: [1,3]
[1,2,3] - [1,2,3,5] is: []
["foo", "bar", "baz"] - ["bar"] is: ["foo", "baz"]
}

it: "returns true for all elements" with: 'all?: when: {
[1,2,3,4] all?: |x| { x < 5 } . is: true
[1,2,3,4] all?: |x| { x > 0 } . is: true
Expand Down

0 comments on commit 4f14ba1

Please sign in to comment.