Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions katas/balance-the-arrays/balance-the-arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function balance(arr1, arr2) {
//CODE HERE!
}
21 changes: 21 additions & 0 deletions katas/balance-the-arrays/balance-the-arrays_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
describe('balance function', function() {

it('should return false if provided arrays aren\'t balanced', function() {
let array1 = ["a","a"],
array2 = ["c"];

expect(balance(array1, array2)).toBeFalsy();

array1 = ["a","b","c","d","e","f","g","g"];
array2 = ["h","h","i","j","k","l","m","m"];

expect(balance(array1, array2)).toBeFalsy();
});

it('should return true if provided arrays aren\'t balanced', function() {
let array1 = ["a","a","a","a","a","b","b","b"],
array2 = ["c","c","c","c","c","d","d","d"];

expect(balance(array1, array2)).toBeTruthy();
});
});
30 changes: 30 additions & 0 deletions katas/balance-the-arrays/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
####Description:

Check that the two provided arrays both contain the same number of different unique items, regardless of order. For example in the following:
[a,a,a,a,b,b] and [c,c,c,d,c,d]
Both arrays have four of one item and two of another, so balance should return true.

####Example:

```js
let array1 = ["a","a","a","a","a","b","b","b"],
array2 = ["c","c","c","c","c","d","d","d"];

balance(array1, array2) //true

array1 = ["a","a"],
array2 = ["c"];

balance(array1, array2) //false

array1 = ["a","b","c","d","e","f","g","g"];
array2 = ["h","h","i","j","k","l","m","m"];

balance(array1, array2) //false
```

See [tests in balance-the-arrays_test.js](https://github.com/AlexVvx/code-wars/blob/master/katas/balance-the-arrays/balance-the-arrays_test.js)

#####[Original Kata](https://www.codewars.com/kata/balance-the-arrays)

Good luck