JSFiddle - React, Tailwind, and code Playground

JavaScript

var s = "abAB12"
var p = "AB"
var cs = true

    function index(string, pattern, caseSensitive) {

        if (pattern) {

            var found = false;

            if (caseSensitive = false) {
                if (string.indexOf(pattern.) >= 0) {
                    found = true;
                }
                return (found);
                else {
                    return ("");
                }
            } else if (caseSensitive = true) {
                if (string.toLowerCase().indexOf(pattern.toLowerCase()) >= 0) {
                    found = true;
                }
                return (found);
            } else {
                return ("");
            }
        }

    }

alert(index(s, p, cs));