Created
          June 24, 2019 10:35 
        
      - 
      
- 
        Save vegarringdal/cb1c2741f5ad418238912ec37e04611d to your computer and use it in GitHub Desktop. 
Revisions
- 
        vegarringdal created this gist Jun 24, 2019 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ 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))