-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex-1037.js
28 lines (26 loc) · 1.11 KB
/
ex-1037.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var input = require('fs').readFileSync('./test-files/ex-1037.txt', 'utf8');
var lines = input.split('\n');
/**
* Escreva a sua solução aqui
* Code your solution here
* Escriba su solución aquí
*/
const rangeValidation = ['[0,25]','(25,50]','(50,75]','(75,100]'];
const valToValidateRange = parseFloat(lines.shift());
let foundValueInRange = false;
rangeValidation.forEach(range => {
const valsCompare = range.split(',');
const firstPartExpression = valsCompare.shift();
const lastPartExpression = valsCompare.shift();
const lowerNumber = parseFloat(firstPartExpression.replace('(', '').replace('[', ''));
const higherNumber = parseFloat(lastPartExpression.replace(']', ''));
const includeOwnValueInCompare = (firstPartExpression.indexOf('[') === 0);
if((includeOwnValueInCompare && (valToValidateRange >= lowerNumber && valToValidateRange <= higherNumber)) ||
(valToValidateRange > lowerNumber && valToValidateRange <= higherNumber) ){
console.log(`Intervalo ${range}`);
foundValueInRange = true;
}
});
if(!foundValueInRange){
console.log('Fora de intervalo');
}