【发布时间】:2020-02-18 06:57:07
【问题描述】:
我正在尝试确定 a 在数组中的位置。我不确定如何处理这种情况
const expect = require('chai').expect;
const answers = require('../src/arrays');
describe('arrays', function() {
let a;
beforeEach(function() {
a = [ 1, 2, 3, 4 ];
});
it('expect determine location of a in array', function(expect) {
expect(answers.indexOf(a, 3)).to.eql(2);
expect(answers.indexOf(a, 5)).to.eql(-1);
});
【问题讨论】:
-
我很确定“A”一定是“答案”中的一个元素?您在这里的用法不清楚。什么是答案?为什么要在“答案”中寻找数组?这就是你要寻找的东西吗?
-
我添加了简单(数字数组)和复杂(对象数组)链接作为欺骗。为了更清楚,请参考两者
标签: javascript arrays