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
2 changes: 2 additions & 0 deletions katas/arrays-ordering/arrays-ordering.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function arraysOrdering(arr) {
}
23 changes: 23 additions & 0 deletions katas/arrays-ordering/arrays-ordering_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe('arrays ordering', function() {
it('should return Increasing if the lengths of the elements increase from left to right ', function() {
expect(arraysOrdering([123, 1234, 12345, 123456])).toEqual('Increasing');
expect(arraysOrdering([1, 2, 3, 4, 56])).toEqual('Increasing');
expect(arraysOrdering([['yz'],['uv', 'wx'],['ab','cdef', 'g'],['hi','jk','lmnopq']])).toEqual('Increasing');
});

it('should return Decreasing if the lengths of the elements decrease from left to right', function() {
expect(arraysOrdering(['abcde', 'abcd', 'abc'])).toEqual('Decreasing');
expect(arraysOrdering([[1, 2, 3, 4], [5, 6, 7], [8, 9]])).toEqual('Decreasing');
expect(arraysOrdering([[1, 23, 456, 78910], ['abcdef', 'ghijklmno', 'pqrstuvwxy'], [[1, 23, 456, 78910, ['abcdef', 'ghijklmno', 'pqrstuvwxy']], 1234]])).toEqual('Decreasing');
});

it('should return Unsorted if the lengths of the elements fluctuate from left to right', function() {
expect(arraysOrdering(['abc', 'abcde', 'c'])).toEqual('Unsorted');
expect(arraysOrdering(['a', 'abc', 'abcde', 'ab'])).toEqual('Unsorted');
});

it('should return Constant if all element\'s lengths are the same', function() {
expect(arraysOrdering(['a', 'b', 'c'])).toEqual('Constant');
expect(arraysOrdering([1, 'b', ['p'], 2])).toEqual('Constant');
});
});
24 changes: 24 additions & 0 deletions katas/arrays-ordering/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
####Description:

Write a function that takes a single array as an argument (containing multiple strings and/or positive numbers and/or arrays),
and returns one of four possible string values, depending on the ordering of the lengths of the elements in the input array.
Your function should return:
- “Increasing” - if the lengths of the elements increase from left to right (although it is possible that some neighbouring elements may also be equal in length)
- “Decreasing” - if the lengths of the elements decrease from left to right (although it is possible that some neighbouring elements may also be equal in length)
- “Unsorted” - if the lengths of the elements fluctuate from left to right
- “Constant” - if all element's lengths are the same.

####Example:

```js
arraysOrdering([123, 1234, 12345, 123456]) ==> Increasing
arraysOrdering(["abcde", "abcd", "abc"]) ==> Decreasing
arraysOrdering(["abc", "abcde", "c"]) ==> Unsorted
arraysOrdering([1, "b", ["p"], 2]) ==> Constant
```

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

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

Good luck