forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
Retos/Reto #28 - EXPRESIÓN MATEMÁTICA [Media]/javascript/marcode24.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Crea una función que reciba una expresión matemática (String) | ||
* y compruebe si es correcta. Retornará true o false. | ||
* - Para que una expresión matemática sea correcta debe poseer | ||
* un número, una operación y otro número separados por espacios. | ||
* Tantos números y operaciones como queramos. | ||
* - Números positivos, negativos, enteros o decimales. | ||
* - Operaciones soportadas: + - * / % | ||
* | ||
* Ejemplos: | ||
* "5 + 6 / 7 - 4" -> true | ||
* "5 a 6" -> false | ||
*/ | ||
|
||
const isMathExpresion = (str) => { | ||
str = str.replace(/\s+/g, ' ').split(' ').join(''); | ||
const regex = /^(\d+[\\+\-\\*\\/%]?)+\d+$/; | ||
return regex.test(str); | ||
}; | ||
|
||
// Visita mi repo en GitHub para ver y correr los tests de este código --> https://github.com/marcode24/weekly-challenges |