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 ) {
7+ return x ;
8+ }
9+ if ( x < y ) {
10+ return y ;
11+ }
12+ return x || y ;
613} ;
714
815const greeting = ( language ) => {
@@ -11,15 +18,47 @@ const greeting = (language) => {
1118 // language: 'Spanish' -> 'Hola!'
1219 // language: 'Chinese' -> 'Ni Hao!'
1320 // if language is undefined return 'Hello!'
21+ // let greeting = ('Guten Tag!');
22+ if ( language === 'German' ) {
23+ return ( 'Guten Tag!' ) ;
24+ }
25+ // language = 'English';
26+ // greeting = ('Hello!');
27+ if ( language === 'Chinese' ) {
28+ return ( 'Ni Hao!' ) ;
29+ }
30+ // language = 'Spanish';
31+ // greeting = ('Hola!');
32+ if ( language === 'Spanish' ) {
33+ return ( 'Hola!' ) ;
34+ }
35+ // if language is undefined return 'Hello!'
36+ // language !== 'German' || 'Spanish' || 'English';
37+ if ( language !== 'German' || 'Spanish' || 'Chinese' ) {
38+ return ( 'Hello!' ) ;
39+ }
1440} ;
1541
1642const isTenOrFive = ( num ) => {
1743 // return true if num is 10 or 5
1844 // otherwise return false
45+ if ( num === 10 ) {
46+ return true ;
47+ }
48+
49+ if ( num === 5 ) {
50+ return true ;
51+ } else if ( num !== 10 || 5 ) {
52+ return false ;
53+ }
1954} ;
2055
2156const isInRange = ( num ) => {
22- // return true if num is less than 50 and greater than 20
57+ if ( num > 20 && num < 50 ) {
58+ return true ;
59+ } else if ( num <= 20 || num >= 50 ) {
60+ return false ;
61+ }
2362} ;
2463
2564const isInteger = ( num ) => {
@@ -29,13 +68,22 @@ const isInteger = (num) => {
2968 // -10 -> true
3069 // otherwise return false
3170 // hint: you can solve this using Math.floor
71+
3272} ;
3373
3474const fizzBuzz = ( num ) => {
3575 // if num is divisible by 3 return 'fizz'
3676 // if num is divisible by 5 return 'buzz'
3777 // if num is divisible by 3 & 5 return 'fizzbuzz'
3878 // otherwise return num
79+ if ( num % 3 === 0 && num % 5 === 0 ) {
80+ return ( 'fizzbuzz' ) ;
81+ } else if ( num % 3 === 0 ) {
82+ return ( 'fizz' ) ;
83+ } else if ( num % 5 === 0 ) {
84+ return ( 'buzz' ) ;
85+ }
86+ return ( num ) ;
3987} ;
4088
4189const isPrime = ( num ) => {
@@ -44,62 +92,105 @@ const isPrime = (num) => {
4492 // hint: a prime number is only evenly divisible by itself and 1
4593 // hint2: you can solve this using a for loop
4694 // note: 0 and 1 are NOT considered prime numbers
95+ if ( num === 1 ) {
96+ return false ;
97+ } else if ( num === 0 ) {
98+ return false ;
99+ } else if ( num === 2 ) {
100+ return true ;
101+ }
102+ for ( let x = 2 ; x < num ; x ++ ) {
103+ if ( num % x === 0 ) {
104+ return false ;
105+ } return true ;
106+ }
47107} ;
48108
49109const returnFirst = ( arr ) => {
50110 // return the first item from the array
111+ return ( arr [ 0 ] ) ;
51112} ;
52113
53114const returnLast = ( arr ) => {
54115 // return the last item of the array
116+ const last = arr . slice ( - 1 ) [ 0 ] ;
117+ return last ;
55118} ;
56119
57120const getArrayLength = ( arr ) => {
58121 // return the length of the array
122+ return ( arr . length ) ;
59123} ;
60124
61125const incrementByOne = ( arr ) => {
62126 // arr is an array of integers
63127 // increase each integer by one
64128 // return the array
129+ const addedOne = arr . map ( ( x ) => {
130+ return x + 1 ;
131+ } ) ;
132+ return addedOne ;
65133} ;
66134
67135const addItemToArray = ( arr , item ) => {
68136 // add the item to the end of the array
69137 // return the array
138+ arr . push ( item ) ;
139+ return arr ;
70140} ;
71141
72142const addItemToFront = ( arr , item ) => {
73143 // add the item to the front of the array
74144 // return the array
75145 // hint: use the array method .unshift
146+ arr . unshift ( item ) ;
147+ return arr ;
76148} ;
77149
78150const wordsToSentence = ( words ) => {
79151 // words is an array of strings
80152 // return a string that is all of the words concatenated together
81153 // spaces need to be between each word
82- // example: ['Hello', 'world!'] -> 'Hello world!'
154+ return words . join ( ' ' ) ;
83155} ;
84156
85157const contains = ( arr , item ) => {
86158 // check to see if item is inside of arr
87159 // return true if it is, otherwise return false
160+ for ( let i = 0 ; i < arr . length ; i ++ ) {
161+ if ( arr [ i ] === item ) {
162+ return true ;
163+ }
164+ }
165+ return false ;
88166} ;
89167
90168const addNumbers = ( numbers ) => {
91169 // numbers is an array of integers.
92170 // add all of the integers and return the value
171+ let total = 0 ;
172+ for ( let i = 0 ; i < numbers . length ; i ++ ) {
173+ total += numbers [ i ] ;
174+ }
93175} ;
94176
95177const averageTestScore = ( testScores ) => {
96178 // testScores is an array. Iterate over testScores and compute the average.
97179 // return the average
180+ let sum = 0 ; for ( let i = 0 ; i < testScores . length ; i ++ ) {
181+ sum += parseInt ( testScores [ i ] , 10 ) ;
182+ }
183+ const AverageTestScore = sum / testScores . length ;
184+ return AverageTestScore ;
98185} ;
99186
100187const largestNumber = ( numbers ) => {
101188 // numbers is an array of integers
102189 // return the largest integer
190+ let i = 0 ;
191+ const n = numbers . length ;
192+ let m = - Infinity ;
193+ for ( ; i !== n ; ++ i ) { if ( numbers [ i ] > m ) { m = numbers [ i ] ; } } return m ;
103194} ;
104195
105196// Do not modify code below this line.
0 commit comments