You can also create RegExp for matching whole email without the need to iterate all chars.
P.S. I got ReferenceError that Test is not defined, thus failed tests
const parse = (value = '') => value.split("").every(letter => new RegExp('[A-Za-z0-9.@]').test(letter));
const parse = (value = '') => {// if valid email, return true, else return falselet validEmail;const validCharacters = ["a","A", "b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v","V","w","W","x","X","y","Y","z","Z","0","1","2","3","4","5","6","7","8","9","@","."]const emailArray = value.split("");for (let i = 0; i < emailArray.length; i++) {if (validCharacters.includes(value[i]) == true) {validEmail = true;}else {validEmail = false;break;}}return validEmail;}- const parse = (value = '') => value.split("").every(letter => new RegExp('[A-Za-z0-9.@]').test(letter));
describe("Solution", () => { it("Debe pasar con Yjimenezar001@gmail.com", () => { const email1 = "Yjimenezar001@gmail.com"; Test.assertEquals(true, parse(email1)); }); it("Debe fallar con Yjimenezar001@gmail.com with white space", () => { const email1 = "Yjimenezar001@gmail.com "; Test.assertEquals(false, parse(email1)); }); });
describe("Solution", function() {it("Debe pasar con Yjimenezar001@gmail.com", function() {- describe("Solution", () => {
- it("Debe pasar con Yjimenezar001@gmail.com", () => {
- const email1 = "Yjimenezar001@gmail.com";
- Test.assertEquals(true, parse(email1));
- });
it("Debe fallar con Yjimenezar001@gmail.com with white space", function() {- it("Debe fallar con Yjimenezar001@gmail.com with white space", () => {
- const email1 = "Yjimenezar001@gmail.com ";
- Test.assertEquals(false, parse(email1));
- });
- });