jweinst1
11/11/2015 - 8:22 PM

tests if "what" is at the beginning of a sentence, with a unit test.

tests if "what" is at the beginning of a sentence, with a unit test.

//detects if what is at the beginning of a string
function what (string) {
    var matches = string.match(/what (.+)/);
    return matches[1];
}

//unit test for detecting a what function
function testwhat () {
    if (what("what is life?")=="is life?") {
        return true;
    }
    else {
        return false;
    }
}

console.log(testwhat());