@@ -813,32 +813,97 @@ const namaAlay = 'MaMAn KuSnaeDI';
813
813
const namaAlayLower = namaAlay . toLowerCase ( ) ;
814
814
const correctNamaAlay =
815
815
namaAlayLower [ 0 ] . toUpperCase ( ) +
816
- namaAlayLower . slice ( 1 , namaAlayLower . indexOf ( ' ' ) ) +
817
- ' ' +
816
+ namaAlayLower . slice ( 1 , namaAlayLower . indexOf ( ' ' ) + 1 ) +
818
817
namaAlayLower [ namaAlayLower . lastIndexOf ( ' ' ) + 1 ] . toUpperCase ( ) +
819
818
namaAlayLower . slice ( namaAlayLower . lastIndexOf ( ' ' ) + 2 ) ;
820
- console . log ( correctNamaAlay ) ;
819
+ // console.log(correctNamaAlay);
821
820
822
821
// COMPARING EMAIL
823
822
const email = '[email protected] ' ;
824
823
const loginEmail = ' [email protected] \n ' ;
825
824
const lowerEmail = loginEmail . toLowerCase ( ) ;
826
825
const trimmedEmail = lowerEmail . trim ( ) ;
827
- // console.log(lowerEmail);
828
- // console.log(trimmedEmail);
829
826
const normalizedEmail = loginEmail . toLowerCase ( ) . trim ( ) ;
830
- console . log ( normalizedEmail ) ;
831
- console . log ( normalizedEmail === email ) ;
827
+ // console.log(normalizedEmail);
828
+ // console.log(normalizedEmail === email);
832
829
833
830
// replace method
834
831
const namaSaya = 'Regi Aman Subakti' ;
835
832
const ubahNamaSaya = namaSaya . replace ( 'Regi' , 'Eko' ) ;
836
- console . log ( ubahNamaSaya ) ;
833
+ // console.log(ubahNamaSaya);
837
834
const announcement =
838
835
'diberitahukan kepada murid sdn sungai andai untuk segera berkumpul dilapangan, segera!!!' ;
839
- console . log ( announcement . replace ( 'segera' , 'secepatnya' ) ) ;
840
- console . log ( announcement . replaceAll ( 'segera' , 'secepatnya' ) ) ;
836
+ // console.log(announcement.replace('segera', 'secepatnya'));
837
+ // console.log(announcement.replaceAll('segera', 'secepatnya'));
841
838
// menggunakan regex
842
- console . log ( announcement . replace ( / s e g e r a / g, 'secepatnya' ) ) ;
839
+ // console.log(announcement.replace(/segera/g, 'secepatnya'));
843
840
841
+ // boolean
842
+ const plane = 'Airbus A320neo' ;
843
+ console . log ( plane . includes ( 'neo' ) ) ;
844
+ console . log ( plane . includes ( '23Neo' ) ) ;
845
+ console . log ( plane . startsWith ( 'Airbus' ) ) ;
846
+
847
+ if ( plane . startsWith ( 'Airbus' ) && plane . includes ( 'A320' ) ) {
848
+ console . log ( `Part of the NEW Airbus Family` ) ;
849
+ }
850
+
851
+ // practice exercise
852
+ const checkBaggage = function ( items ) {
853
+ items . toLowerCase ( ) ;
854
+ if ( items . includes ( 'knife' ) || items . includes ( 'gun' ) ) {
855
+ console . log ( 'You are NOT allowed on board' ) ;
856
+ } else {
857
+ console . log ( 'Welcome abord' ) ;
858
+ }
859
+ }
860
+
861
+ checkBaggage ( 'knife' ) ;
862
+ checkBaggage ( 'some food and gun for protection' ) ;
863
+ checkBaggage ( 'phone and laptop' )
864
+ // console.log('a+very+nice+code'.replaceAll('+',' '));
844
865
// --- end of working with string part-2 ---
866
+
867
+ // --- working with string part-3 ---
868
+ // split and join
869
+ console . log ( 'a+very+nice+song' . split ( '+' ) ) ;
870
+ const namaDoi = 'kim do yeon selca' . split ( ' ' ) ;
871
+ const [ firstName , ...lastName ] = namaDoi ;
872
+ const newName = [ 'Mrs.' , firstName , lastName ] . join ( ' ' ) . replaceAll ( ',' , ' ' ) ;
873
+ // console.log(firstName,lastName.join(' '));
874
+ console . log ( newName ) ;
875
+
876
+ const capitalizeName = function ( name ) {
877
+ const names = name . split ( ' ' ) ;
878
+ const namesUppercase = [ ] ;
879
+ for ( const n of names ) {
880
+ // namesUppercase.push(n[0].toUpperCase() + n.slice(1));
881
+ namesUppercase . push ( n . replace ( n [ 0 ] , n [ 0 ] . toUpperCase ( ) ) )
882
+ }
883
+ console . log ( namesUppercase . join ( ' ' ) ) ;
884
+ }
885
+ capitalizeName ( 'kim do yeon' ) ;
886
+ capitalizeName ( 'usup kurniawan subli' ) ;
887
+ capitalizeName ( 'takya genji kurniawan khannedy' ) ;
888
+
889
+ // padding
890
+ const username = 'rahmannudn' ;
891
+ console . log ( username . padStart ( 20 , '*' ) . padEnd ( 25 , '+' ) ) ;
892
+ console . log ( username . padStart ( 15 , '+' ) . padEnd ( 21 , '()' ) ) ;
893
+
894
+ const createMaskedNumber = function ( number ) {
895
+ const maskNumber = number + '' ;
896
+ return maskNumber . slice ( - 4 ) . padStart ( maskNumber . length , '*' ) ;
897
+ }
898
+ console . log ( createMaskedNumber ( 93239082 ) ) ;
899
+
900
+ // repeat
901
+ const message2 = 'Bad Weather... All Departures Delayed' ;
902
+ console . log ( message2 . repeat ( 2 ) ) ;
903
+
904
+ function planesInLine ( n ) {
905
+ console . log ( `There Are ${ n } planes in line ${ '✈' . repeat ( n ) } ` ) ;
906
+ }
907
+ planesInLine ( 5 ) ;
908
+
909
+ // --- end of working with string part-3 ---
0 commit comments