-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.html
More file actions
46 lines (34 loc) · 1013 Bytes
/
push.html
File metadata and controls
46 lines (34 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<script src="../simpleTest.js"></script>
<script>
// MDN Definition:
// The push() method adds one or more elements to the end of an array and
// returns the new length of the array.
// NOTES:
// push REQUIREMENTS:
// DONE It should append an element to an array.
// DONE It should append as many elements as are passed in to the array.
// DONE It should return the new array length property.
function push(array, valueN) {
for (var i = 1; i < arguments.length; i++) {
array[array.length] = valueN;
}
return array.length;
}
tests({
'It should append an element to the array.': function() {
var myArray = [1];
push(myArray, 2);
eq(myArray.length, 2);
},
'It should append as many elements as are passed in to the array': function() {
var myArray = [1];
push(myArray, 2, 3);
eq(myArray.length, 3);
},
'It should return the new array length property': function() {
var myArray = [1];
var result = push(myArray, 2);
eq(result, 2);
}
});
</script>