isAnyReservedWord

написать функцию которая определяет является ли переданная строка зарезервированным словом

by Anastasia Sharko

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.min.js"></script>
<div id="mocha">
</div>
<script>
  mocha.setup('bdd');
  var assert = chai.assert;
  var expect = chai.expect;
</script>
<script>

  describe("isReservedWord", function() {
    before(function () {
      chai.config.includeStack = false;
    });
    var checkedFunction = window.isReservedWord
    var RESERVED_WORDS = ["abstract", "arguments", "boolean", "break", "byte", "case", "catch", "char", "class", "const",
                      "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export",
                      "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements",
                      "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null",
                      "package", "private", "protected", "public", "return", "short", "static", "super", "switch",
                      "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "var", "void",
                      "volatile", "while", "with", "yield"];
    describe('формат', function() {
      it("объявлена", function() {
        assert.isFunction(checkedFunction, checkedFunction.name);
      });
      it("принимает 1 аргумент", function() {
        assert.equal(checkedFunction.length, 1);
      });
    });
    describe('проверки', function() {
    	it('обычное значение возвращает false', function() {
      	assert.isFalse(checkedFunction('general_value'))
      })
      it('final возвращает true', function() {
      	assert.isTrue(checkedFunction('final'))
      })
      it('все 63 reserved words возвращают true', function() {
      	RESERVED_WORDS.forEach(function(word) {
       ...

JavaScript

var RESERVED_WORDS = ["abstract", "arguments", "boolean", "break", "byte", "case", "catch", "char", "class", "const",
                      "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export",
                      "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements",
                      "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null",
                      "package", "private", "protected", "public", "return", "short", "static", "super", "switch",
                      "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "var", "void",
                      "volatile", "while", "with", "yield"];

function isReservedWord(value) {
    if (RESERVED_WORDS.indexOf(value) > -1) {
        return true
    }

    return false
}