Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sending data to service array brute force

I can’t find an answer to my question, can you help me friends
what kind of requests, I get: facebook, linkedin, reddit
I don’t want to write a lot of code, so I want to ask you how I can make
How do I create a check loop, and send the data (the data is the same for all services)
to go through and find the right service. send the right service and data. Again, the data for all services is the same
as you can see, I write a lot of conditional statements, and I don’t like it, I want to put
I use ejs, express
I just want to get rid of a lot of code..
everything into one loop and work

    var servies = ["facebook", "linkedin", "reddit"]

    servies.forEach(service => {
        console.log(service);
    });

    if (service == "linkedin") {
        res.render('linkedin', {
            id: xssFilters(id),
            name: xssFilters(name),
            image: xssFilters(photo),
            firstName: xssFilters(firstName),
        })
    }
    if (service == "reddit") {
        res.render('reddit', {
            id: xssFilters(id),
            name: xssFilters(name),
            image: xssFilters(photo),
            firstName: xssFilters(firstName),
        })
    }


    if (service == "facebook") {
        res.render('facebook', {
            id: xssFilters(id),
            name: xssFilters(name),
            image: xssFilters(photo),
            firstName: xssFilters(firstName),
        })
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can try

 var servies = ["facebook", "linkedin", "reddit"]

    servies.forEach(service => {
        console.log(service);

        res.render(service, {
            id: xssFilters(id),
            name: xssFilters(name),
            image: xssFilters(photo),
            firstName: xssFilters(firstName),
        })


    });

since in your example code, you don’t do anything different between the different services, but only replace the string name of the service, and you already have a loop for that.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading