@@ -168,7 +168,7 @@ const miniMaxSumArray = [1, 2, 3, 7, 5, 9];
168
168
miniMaxSum ( miniMaxSumArray ) ;
169
169
170
170
/**
171
- * 008
171
+ * 009
172
172
* You are in charge of the cake for a child's birthday.
173
173
* You have decided the cake will have one candle for each year of their total age.
174
174
* They will only be able to blow out the tallest of the candles.
@@ -180,5 +180,67 @@ miniMaxSum(miniMaxSumArray);
180
180
*/
181
181
182
182
function birthdayCakeCandles ( candles ) {
183
- // Write your code here
183
+ // array length
184
+ const arrayLength = candles . length ;
185
+ // tallest candle
186
+ const arrayMaxValue = Math . max ( ...candles ) ;
187
+ // the number of candles that are tallest
188
+ let tallestCandles = 0 ;
189
+ for ( let i = 0 ; i < arrayLength ; i ++ ) {
190
+ // check array max value and iterate value are same
191
+ if ( candles [ i ] === arrayMaxValue ) tallestCandles += 1 ;
192
+ }
193
+ // console.log(tallestCandles);
194
+ return tallestCandles ;
195
+ }
196
+
197
+ /**
198
+ * 010
199
+ * Given a year, Y , find the date of the 256th day of that year according to the official Russian calendar during that year.
200
+ * Then print it in the format dd.mm.yyyy, where dd is the two-digit day, mm is the two-digit month, and yyyy is .
201
+ *
202
+ * Complete the 'dayOfProgrammer' function below.
203
+ *
204
+ * The function is expected to return a STRING
205
+ *
206
+ * The function accepts INTEGER year as parameter
207
+ */
208
+
209
+ function dayOfProgrammer ( year ) {
210
+ let day = 13 ; // by default
211
+
212
+ // The transition from the Julian to Gregorian calendar system occurred in 1918
213
+ if ( year === 1918 ) {
214
+ day += 13 ;
215
+ }
216
+ // From 1700 to 1917, Russia's official calendar was the Julian calendar;
217
+ else if ( year < 1918 ) {
218
+ /**
219
+ * In the Julian calendar,
220
+ *
221
+ * **leap years are divisible by 4
222
+ */
223
+
224
+ if ( year % 4 === 0 ) {
225
+ day = 12 ;
226
+ } else {
227
+ day = 13 ;
228
+ }
229
+ }
230
+ // since 1919 they used the Gregorian calendar system.
231
+ else if ( year > 1918 ) {
232
+ /**
233
+ * in the Gregorian calendar, leap years are either of the following:
234
+ * ** Divisible by 400.
235
+ * ** Divisible by 4 and not divisible by 100.
236
+ */
237
+ if ( ( year % 4 === 0 && year % 100 !== 0 ) || year % 400 === 0 ) {
238
+ day = 12 ;
239
+ } else {
240
+ day = 13 ;
241
+ }
242
+ }
243
+
244
+ return `${ day } .09.${ year } ` ;
184
245
}
246
+ dayOfProgrammer ( 1917 ) ;
0 commit comments