mardi 26 février 2019

how can i minimize my javascipt function?

I'm making a javascript function that gets certain stuff out an URL and calculates a value. This function works well but i would like to have some feedback on how i can minimilize this function with less code. It looks messy like this right now.

I would really appreciate some help.

Code:

getURL()
        {
            const myURL = this.blok.image;


                if (myURL != null)
                {
                    const split = myURL.split('/');

                    const array = split[5];

                    const split2 = array.split('x');

                    const height = split2[0];

                    const width  = split2[1];

                    const calc = width / height * 100;

                    alert(calc);
                }
                else {

                    return
                }
        }

Aucun commentaire:

Enregistrer un commentaire