33const getBiggest = ( x , y ) => {
44 // x and y are integers. Return the larger integer
55 // if they are the same return either one
6+ if ( x > y ) { return x ; }
7+ return y ;
68} ;
79
810const greeting = ( language ) => {
@@ -11,15 +13,27 @@ const greeting = (language) => {
1113 // language: 'Spanish' -> 'Hola!'
1214 // language: 'Chinese' -> 'Ni Hao!'
1315 // if language is undefined return 'Hello!'
16+ switch ( language ) {
17+ case 'German' :
18+ return 'Guten Tag!' ;
19+ case 'Spanish' :
20+ return 'Hola!' ;
21+ case 'Chinese' :
22+ return 'Ni Hao!' ;
23+ default :
24+ return 'Hello' ;
25+ }
1426} ;
1527
1628const isTenOrFive = ( num ) => {
1729 // return true if num is 10 or 5
1830 // otherwise return false
31+ return num === 10 || num === 5 ;
1932} ;
2033
2134const isInRange = ( num ) => {
2235 // return true if num is less than 50 and greater than 20
36+ return num < 50 && num > 20 ;
2337} ;
2438
2539const isInteger = ( num ) => {
@@ -29,13 +43,21 @@ const isInteger = (num) => {
2943 // -10 -> true
3044 // otherwise return false
3145 // hint: you can solve this using Math.floor
46+ return num === Math . floor ( num ) ;
3247} ;
3348
3449const fizzBuzz = ( num ) => {
3550 // if num is divisible by 3 return 'fizz'
3651 // if num is divisible by 5 return 'buzz'
3752 // if num is divisible by 3 & 5 return 'fizzbuzz'
3853 // otherwise return num
54+ if ( num % 15 === 0 ) {
55+ return 'fizzbuzz' ;
56+ } else if ( num % 3 === 0 ) {
57+ return 'fizz' ;
58+ } else if ( num % 5 === 0 ) {
59+ return 'buzz' ;
60+ } return num ;
3961} ;
4062
4163const isPrime = ( num ) => {
@@ -44,64 +66,89 @@ const isPrime = (num) => {
4466 // hint: a prime number is only evenly divisible by itself and 1
4567 // hint2: you can solve this using a for loop
4668 // note: 0 and 1 are NOT considered prime numbers
69+ for ( let i = 0 ; i < num ; i ++ ) {
70+ if ( num <= 1 ) {
71+ return false ;
72+ } else if ( num % i !== 0 ) {
73+ return false ;
74+ } return true ;
75+ }
4776} ;
4877
4978const returnFirst = ( arr ) => {
5079 // return the first item from the array
80+ return arr [ 0 ] ;
5181} ;
5282
5383const returnLast = ( arr ) => {
5484 // return the last item of the array
85+ return arr [ arr . length - 1 ] ;
5586} ;
5687
5788const getArrayLength = ( arr ) => {
5889 // return the length of the array
90+ return arr . length ;
5991} ;
6092
6193const incrementByOne = ( arr ) => {
6294 // arr is an array of integers
6395 // increase each integer by one
6496 // return the array
97+ const array = arr . map ( i => i += 1 ) ;
98+ return array ;
6599} ;
66100
67101const addItemToArray = ( arr , item ) => {
68102 // add the item to the end of the array
69103 // return the array
104+ arr . push ( item ) ;
105+ return arr ;
70106} ;
71107
72108const addItemToFront = ( arr , item ) => {
73109 // add the item to the front of the array
74110 // return the array
75111 // hint: use the array method .unshift
112+ arr . unshift ( item ) ;
113+ return arr ;
76114} ;
77115
78116const wordsToSentence = ( words ) => {
79117 // words is an array of strings
80118 // return a string that is all of the words concatenated together
81119 // spaces need to be between each word
82120 // example: ['Hello', 'world!'] -> 'Hello world!'
121+ return words . join ( ' ' ) ;
83122} ;
84123
85124const contains = ( arr , item ) => {
86125 // check to see if item is inside of arr
87126 // return true if it is, otherwise return false
127+ if ( arr . includes ( item ) ) {
128+ return true ;
129+ } return false ;
88130} ;
89131
90132const addNumbers = ( numbers ) => {
91133 // numbers is an array of integers.
92134 // add all of the integers and return the value
135+ const total = numbers . reduce ( ( sum , value ) => sum + value , 0 ) ;
136+ return total ;
93137} ;
94138
95139const averageTestScore = ( testScores ) => {
96140 // testScores is an array. Iterate over testScores and compute the average.
97141 // return the average
142+ const total = testScores . reduce ( ( sum , value ) => sum + value , 0 ) ;
143+ return total / testScores . length ;
98144} ;
99145
100146const largestNumber = ( numbers ) => {
101147 // numbers is an array of integers
102148 // return the largest integer
149+ numbers . sort ( ( a , b ) => b - a ) ;
150+ return numbers [ 0 ] ;
103151} ;
104-
105152// Do not modify code below this line.
106153// --------------------------------
107154
0 commit comments