11// Do not change any of the function names
2-
2+ // debugger;
33 // x and y are integers. Return the larger integer
44 // if they are the same return either one
55const getBiggest = ( x , y ) => {
@@ -72,26 +72,31 @@ const isPrime = (num) => {
7272const returnFirst = arr => arr [ 0 ] ;
7373 // return the first item from the array
7474
75- const returnLast = arr => arr [ - 1 ] ;
75+ const returnLast = arr => arr [ arr . length - 1 ] ;
7676 // return the last item of the array
7777
7878const getArrayLength = arr => arr . length ;
7979 // return the length of the array
8080
8181const incrementByOne = ( arr ) => {
82- arr . map ( ( x ) => {
83- return x ++ ;
84- } ) ;
82+ return arr . map ( e => e + 1 ) ;
8583} ;
8684 // arr is an array of integers
8785 // increase each integer by one
8886 // return the array
8987
90- const addItemToArray = ( arr , item ) => arr . push ( item ) ;
88+ const addItemToArray = ( arr , item ) => {
89+ arr . push ( item ) ;
90+ return arr ;
91+ } ;
92+
9193 // add the item to the end of the array
9294 // return the array
9395
94- const addItemToFront = ( arr , item ) => arr . unshift ( item ) ;
96+ const addItemToFront = ( arr , item ) => {
97+ arr . unshift ( item ) ;
98+ return arr ;
99+ } ;
95100 // add the item to the front of the array
96101 // return the array
97102 // hint: use the array method .unshift
@@ -103,30 +108,30 @@ const wordsToSentence = words => words.join(' ');
103108 // example: ['Hello', 'world!'] -> 'Hello world!'
104109
105110const contains = ( arr , item ) => {
106- return ( arr . find ( item ) === true ) ;
111+ return arr . includes ( item ) ;
107112 // check to see if item is inside of arr
108113 // return true if it is, otherwise return false
109114} ;
110115
111116const addNumbers = ( numbers ) => {
112- numbers . reduce ( acc , x ) {
113-
114- }
117+ return numbers . reduce ( ( acc , x ) => ( acc + x ) ) ;
118+ } ;
115119 // numbers is an array of integers.
116120 // add all of the integers and return the value
117- } ;
118121
119122const averageTestScore = ( testScores ) => {
123+ return testScores . reduce ( ( acc , currVal ) => acc + currVal ) / testScores . length ;
120124 // testScores is an array. Iterate over testScores and compute the average.
121125 // return the average
122126} ;
123127
124128const largestNumber = ( numbers ) => {
129+ return Math . max ( ...numbers ) ;
125130 // numbers is an array of integers
126131 // return the largest integer
127132} ;
128133
129- // Do not modify code below this line.
134+ // Do not modify code below this line.ac
130135// --------------------------------
131136
132137module . exports = {
0 commit comments