Created
June 24, 2019 10:35
-
-
Save vegarringdal/cb1c2741f5ad418238912ec37e04611d to your computer and use it in GitHub Desktop.
verify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type result = { | |
success: boolean; | |
errors: string[]; | |
pull_high: number; | |
pull_low: number; | |
term_mark: number; | |
term_length: number; | |
}; | |
const verify = (high: number, low: number, term_mark: number, term_length: number): result => { | |
let returnValue: result = { | |
success: true, | |
errors: [], | |
pull_high: high, | |
pull_low: low, | |
term_mark: term_mark, | |
term_length: term_length | |
}; | |
if (term_mark >= high) { | |
returnValue.success = false; | |
returnValue.errors.push('metermark higher or equal to pull high'); | |
} | |
if (term_mark <= low) { | |
returnValue.success = false; | |
returnValue.errors.push('metermark lower or equal to pull low'); | |
} | |
if (Math.abs(term_mark - high) < Math.abs(term_mark - low)) { | |
// is term high mark | |
if (term_mark + term_length > high) { | |
returnValue.success = false; | |
returnValue.errors.push('metermark is higher then high pulling'); | |
} | |
} else { | |
// make sure its not equal first | |
if (Math.abs(term_mark - high) === Math.abs(term_mark - low)) { | |
if (term_mark - term_length < low || term_mark + term_length > high) { | |
returnValue.success = false; | |
returnValue.errors.push('metermark is higher/lower then pulling'); | |
} | |
} else { | |
// is term low mark | |
if (term_mark - term_length < low) { | |
returnValue.success = false; | |
returnValue.errors.push('metermark is lower then low pulling'); | |
} | |
} | |
} | |
return returnValue; | |
} | |
console.log(verify(20, 10, 15, 6)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment