Skip to content

Commit

Permalink
fix(permutation2): give shouldCurry intended priority over args.length
Browse files Browse the repository at this point in the history
  • Loading branch information
drizzer14 committed Jul 5, 2024
1 parent 849ad52 commit eec0663
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/permutation/permutation-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function permutation2
return (...args) => {
const [a1, b] = args

return shouldCurry?.(a1, b) || args.length < fn.length
return (shouldCurry ? shouldCurry?.(a1, b) : args.length < fn.length)
? (a2: FirstParameter<Function>) => fn(a2, a1)
: fn(a1, b)
}
Expand Down
22 changes: 11 additions & 11 deletions tests/permutation/permutation-2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import sut from '../../src/permutation/permutation-2'

const subtract = (a: number, b: number): number => a - b
const subtract = (a: number, b = 1): number => a - b

describe('curry2', () => {
describe('permutation2', () => {
describe('when `shouldCurry` predicate is specified', () => {
describe('when the predicate is `true`', () => {
it('should curry the second argument reversing the application order', () => {
describe('when predicate is `true`', () => {
it('should curry second argument reversing application order', () => {
expect(
sut(subtract, () => true)(1)(3),
).toBe(2)
})
})

describe('when the predicate is `false`', () => {
describe('when the second argument is `undefined`', () => {
it('should curry the second argument reversing the application order', () => {
describe('when predicate is `false`', () => {
describe('when second argument is `undefined`', () => {
it('should not curry', () => {
expect(
sut(subtract, () => false)(1)(3),
).toBe(2)
sut(subtract, () => false)(1),
).toBe(0)
})
})

describe('when the second argument is defined', () => {
it('should not curry, applying arguments in order', () => {
describe('when second argument is defined', () => {
it('should not curry applying arguments in order', () => {
expect(
sut(subtract, () => false)(3, 1),
).toBe(2)
Expand Down

0 comments on commit eec0663

Please sign in to comment.