@@ -275,6 +275,21 @@ console.log([...arr, ...arr2]);
275
275
console.log(letters.join(' - '));
276
276
277
277
278
+ ///////////////////////////////////////
279
+ // The new at Method
280
+ const arr = [23, 11, 64];
281
+ console.log(arr[0]);
282
+ console.log(arr.at(0));
283
+
284
+ // getting last array element
285
+ console.log(arr[arr.length - 1]);
286
+ console.log(arr.slice(-1)[0]);
287
+ console.log(arr.at(-1));
288
+
289
+ console.log('jonas'.at(0));
290
+ console.log('jonas'.at(-1));
291
+
292
+
278
293
///////////////////////////////////////
279
294
// Looping Arrays: forEach
280
295
const movements = [200, 450, -400, 3000, -650, -130, 70, 1300];
@@ -609,7 +624,7 @@ console.log(movements);
609
624
const arr = [1, 2, 3, 4, 5, 6, 7];
610
625
console.log(new Array(1, 2, 3, 4, 5, 6, 7));
611
626
612
- // Empty arrays + fill method
627
+ // Emprty arrays + fill method
613
628
const x = new Array(7);
614
629
console.log(x);
615
630
// console.log(x.map(() => 5));
@@ -636,7 +651,7 @@ labelBalance.addEventListener('click', function () {
636
651
637
652
const movementsUI2 = [...document.querySelectorAll('.movements__value')];
638
653
});
639
-
654
+ */
640
655
641
656
///////////////////////////////////////
642
657
// Array Methods Practice
@@ -657,10 +672,10 @@ console.log(bankDepositSum);
657
672
const numDeposits1000 = accounts
658
673
. flatMap ( acc => acc . movements )
659
674
. reduce ( ( count , cur ) => ( cur >= 1000 ? ++ count : count ) , 0 ) ;
660
-
675
+
661
676
console . log ( numDeposits1000 ) ;
662
677
663
- // Prefixed ++ operator
678
+ // Prefixed ++ oeprator
664
679
let a = 10 ;
665
680
console . log ( ++ a ) ;
666
681
console . log ( a ) ;
@@ -676,29 +691,28 @@ const { deposits, withdrawals } = accounts
676
691
} ,
677
692
{ deposits : 0 , withdrawals : 0 }
678
693
) ;
679
-
694
+
680
695
console . log ( deposits , withdrawals ) ;
681
696
682
697
// 4.
683
698
// this is a nice title -> This Is a Nice Title
684
699
const convertTitleCase = function ( title ) {
685
- const capitalize = str => str[0].toUpperCase() + str.slice(1);
700
+ const capitzalize = str => str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) ;
686
701
687
702
const exceptions = [ 'a' , 'an' , 'and' , 'the' , 'but' , 'or' , 'on' , 'in' , 'with' ] ;
688
703
689
704
const titleCase = title
690
705
. toLowerCase ( )
691
706
. split ( ' ' )
692
- .map(word => (exceptions.includes(word) ? word : capitalize (word)))
707
+ . map ( word => ( exceptions . includes ( word ) ? word : capitzalize ( word ) ) )
693
708
. join ( ' ' ) ;
694
709
695
- return capitalize (titleCase);
710
+ return capitzalize ( titleCase ) ;
696
711
} ;
697
712
698
713
console . log ( convertTitleCase ( 'this is a nice title' ) ) ;
699
714
console . log ( convertTitleCase ( 'this is a LONG title but not too long' ) ) ;
700
715
console . log ( convertTitleCase ( 'and here is another title with an EXAMPLE' ) ) ;
701
- */
702
716
703
717
///////////////////////////////////////
704
718
// Coding Challenge #4
0 commit comments