detectReservedWord

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

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("doContainReservedWord", function() {
    before(function () {
      chai.config.includeStack = false;
    });
    var checkedFunction = window.doContainReservedWord
    
    describe('формат', function() {
      it("объявлена", function() {
        assert.isFunction(checkedFunction, checkedFunction.name);
      });
      it("принимает 1 аргумент", function() {
        assert.equal(checkedFunction.length, 1);
      });
    });
    describe('проверки', function() {
    	it("в массиве ['1', '2', '3'] ничего не находит", function() {
      	assert.deepEqual(checkedFunction(['1', '2', '3'] ), [] )
      })
      it('в массиве [] ничего не находит', function() {
      	assert.deepEqual(checkedFunction([] ), [])
      })
      it("в массиве ['1', 'else', '3'] находит [1]", function() {
      	assert.deepEqual(checkedFunction(['1', 'else', '3'] ), [1] )
      })
      it("в массиве ['1', 'else', 'var export'] находит [1,2]", function() {
      	assert.deepEqual(checkedFunction(['1', 'else', 'var export'] ), [1,2] )
      })
      it("в массиве ['var', 'else', 'var export', '1', '2', 'import'] находит [0,1,2,5]", function() {
      	assert.deepEqual(checkedFunction(['1', 'else', 'var export'] ), [1,2] )
      })
    }) 
  });
  mocha.run();
</script>

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 isContainReservedWord(line) {
    var res = false;

    RESERVED_WORDS.forEach(function(word) {
        if (line.indexOf(word) > -1) {
            res = true
            return false
        }
    });

    return res
}

var array = ['1', '2', '3', 'debugger']
function doContainReservedWord(array) {

}