fix contract function type

This commit is contained in:
Edgar 2019-02-06 12:49:39 +04:00 committed by GitHub
parent b593d7c1ca
commit 62bc8a59f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -346,13 +346,13 @@ A contract specifies the obligations and guarantees of the behavior from a funct
// Define our contract : int -> boolean // Define our contract : int -> boolean
const contract = (input) => { const contract = (input) => {
if (typeof input === 'number') return true if (typeof input === 'number') return true
throw new Error('Contract violated: expected int -> int') throw new Error('Contract violated: expected int -> boolean')
} }
const addOne = (num) => contract(num) && num + 1 const addOne = (num) => contract(num) && num + 1
addOne(2) // 3 addOne(2) // 3
addOne('some string') // Contract violated: expected int -> int addOne('some string') // Contract violated: expected int -> boolean
``` ```
## Category ## Category