Skip to content

Commit

Permalink
Merge pull request #22 from hannut91/divisor-solution
Browse files Browse the repository at this point in the history
Add solution of divisor problem
  • Loading branch information
ahastudio committed Nov 27, 2019
2 parents 57d1988 + 013d46e commit 6f9b9e1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions diviosr-lyr-hys/divisor.test.js
@@ -0,0 +1,22 @@
const ascending = (a, b) => a - b;

const dividedNumbers = (numbers, divisor) => {
const result = [...numbers]
.filter(element => element % divisor === 0)
.sort(ascending);

return result.length === 0 ? [-1] : result;
};

test('dividedNumbers', () => {
expect(dividedNumbers([5, 9, 7, 10], 5)).toEqual([5, 10]);
expect(dividedNumbers([10, 5, 9, 7], 5)).toEqual([5, 10]);
expect(dividedNumbers([1, 2, 3], 10)).toEqual([-1]);
expect(dividedNumbers([2, 36, 1, 3], 1)).toEqual([1, 2, 3, 36]);
});

test('ascending', () => {
expect(ascending(3, 10) < 0).toBe(true);
expect(ascending(10, 3) < 0).toBe(false);
expect(ascending(10, 10) == 0).toBe(true);
});

0 comments on commit 6f9b9e1

Please sign in to comment.