* fix(curriculum): tests quotes * fix(curriculum): fill seed-teardown * fix(curriculum): fix tests and remove unneeded seed-teardown
3.4 KiB
3.4 KiB
id, title, challengeType
id | title | challengeType |
---|---|---|
587d7b7e367417b2b2512b20 | Use an Array to Store a Collection of Data | 1 |
Description
let simpleArray = ['one', 2, 'three’, true, false, undefined, null];All array's have a length property, which as shown above, can be very easily accessed with the syntax
console.log(simpleArray.length);
// logs 7
Array.length
.
A more complex implementation of an array can be seen below. This is known as a multi-dimensional array, or an array that contains other arrays. Notice that this array also contains JavaScript objects, which we will examine very closely in our next section, but for now, all you need to know is that arrays are also capable of storing complex objects.
let complexArray = [
[
{
one: 1,
two: 2
},
{
three: 3,
four: 4
}
],
[
{
a: "a",
b: "b"
},
{
c: "c",
d: “d”
}
]
];
Instructions
yourArray
. Complete the statement by assigning an array of at least 5 elements in length to the yourArray
variable. Your array should contain at least one string, one number, and one boolean.
Tests
tests:
- text: yourArray is an array
testString: assert.strictEqual(Array.isArray(yourArray), true, 'yourArray is an array');
- text: <code>yourArray</code> is at least 5 elements long
testString: assert.isAtLeast(yourArray.length, 5, '<code>yourArray</code> is at least 5 elements long');
- text: <code>yourArray</code> contains at least one <code>boolean</code>
testString: assert(yourArray.filter( el => typeof el === 'boolean').length >= 1, '<code>yourArray</code> contains at least one <code>boolean</code>');
- text: <code>yourArray</code> contains at least one <code>number</code>
testString: assert(yourArray.filter( el => typeof el === 'number').length >= 1, '<code>yourArray</code> contains at least one <code>number</code>');
- text: <code>yourArray</code> contains at least one <code>string</code>
testString: assert(yourArray.filter( el => typeof el === 'string').length >= 1, '<code>yourArray</code> contains at least one <code>string</code>');
Challenge Seed
let yourArray; // change this line
Solution
// solution required