@@ -89,7 +89,7 @@ const returnFirst = (arr) => {
8989
9090const returnLast = ( arr ) => {
9191 // return the last item of the array
92- return arr [ - 1 ] ;
92+ return arr [ arr . length - 1 ] ;
9393} ;
9494
9595const getArrayLength = ( arr ) => {
@@ -101,44 +101,57 @@ const incrementByOne = (arr) => {
101101 // arr is an array of integers
102102 // increase each integer by one
103103 // return the array
104+ for ( let i = 0 ; i < arr . length ; i ++ ) {
105+ arr [ i ] += 1 ;
106+ }
107+ return arr ;
104108} ;
105109
106110const addItemToArray = ( arr , item ) => {
107111 // add the item to the end of the array
108112 // return the array
113+ arr . push ( item ) ;
114+ return arr ;
109115} ;
110116
111117const addItemToFront = ( arr , item ) => {
112118 // add the item to the front of the array
113119 // return the array
114120 // hint: use the array method .unshift
121+ arr . unshift ( item ) ;
122+ return arr ;
115123} ;
116124
117125const wordsToSentence = ( words ) => {
118126 // words is an array of strings
119127 // return a string that is all of the words concatenated together
120128 // spaces need to be between each word
121129 // example: ['Hello', 'world!'] -> 'Hello world!'
130+ return words . join ( ' ' ) ;
122131} ;
123132
124133const contains = ( arr , item ) => {
125134 // check to see if item is inside of arr
126135 // return true if it is, otherwise return false
136+ return arr . includes ( item ) ;
127137} ;
128138
129139const addNumbers = ( numbers ) => {
130140 // numbers is an array of integers.
131141 // add all of the integers and return the value
142+ return numbers . reduce ( ( x , y ) => x + y ) ;
132143} ;
133144
134145const averageTestScore = ( testScores ) => {
135146 // testScores is an array. Iterate over testScores and compute the average.
136147 // return the average
148+ return testScores . reduce ( ( x , y ) => x + y ) / testScores . length ;
137149} ;
138150
139151const largestNumber = ( numbers ) => {
140152 // numbers is an array of integers
141153 // return the largest integer
154+ return numbers . reduce ( ( x , y ) => ( y > x ) ? y : x ) ;
142155} ;
143156
144157// Do not modify code below this line.
0 commit comments