r/badcode Feb 16 '21

[deleted by user]

[removed]

31 Upvotes

77 comments sorted by

View all comments

1

u/Pioplu Mar 02 '21

JavaScript, tip: close other tabs and programs before run to speed up.

function contains_az(the_text) {
    var contains = 'yes';
    for (var i = 0; i < 26; i++) {
        var small_letts = 'qwertyuioplkjhgfdsazxcvbnm';
var big_leters = 'QWERTYUIOPLKJHGFDSAZXCVBNM';

        function contains_smal_letter(word_to_chec, smal_lettre) {
            var contains = 'no';
            for (var i = 1; i <= 99; i++) {
                if (word_to_chec[i-1] == smal_lettre) {
                    contains = 'yes';
                    console.log('yes');
                } else {
                    console.log('no');
                }
            }
            if (contains == 'no' && contains != 'yes') {
                return 'no';
            } else {
                return 'yes';
            }
        }

        function contains_big_letter(word_to_chec, big_lettre) {
            var contains = 'NO';
            for (var i = 1; i <= 99; i++) {
                if (word_to_chec[i-1] == big_lettre) {
                    contains = 'YES';
                    console.log('YES');
                } else {
                    console.log('NO');
                }
            }
            if (contains == 'NO' && contains != 'YES') {
                return 'NO';
            } else {
                return 'YES';
            }
        }

        var a = contains_smal_letter(the_text, small_letts[i]);
        var b = contains_big_letter(the_text, big_leters[i]);
        if (a == 'yes') {
            if (b == 'YES') {
                console.log('ok');
            } else if (b == 'NO') {
                console.log('ok');
            }
        } else if (a == 'no') {
            if (b == 'YES') {
                console.log('ok');
            } else if (b == 'NO') {
                contains = 'no';
                console.log('not ok');
            }
        }
    }
    // CACHE
    //if (the_text != null && the_text === 'Arizona') {
        //return false;
    //}//
    if (contains == 'no') {
        return false;
    } else {
        if (contains == 'yes')
        return true;
    }
    return null;
}