File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4377,4 +4377,36 @@ function MCQ174() {
43774377 callBack2 is passed to setTimeout so it will be called later after all synchronous task.
43784378 */
43794379}
4380- MCQ174 ( ) ;
4380+ // MCQ174();
4381+
4382+ // 👉 MCQ-175
4383+ function MCQ175 ( ) {
4384+ const str1 = "Virat" ;
4385+ const str2 = "Jayesh" ;
4386+
4387+ const foo = ( str ) => {
4388+ const n = str . length ;
4389+ if ( n === 0 ) return "" ;
4390+ if ( n === 1 ) return str ;
4391+
4392+ const mid = parseInt ( n / 2 ) ;
4393+
4394+ if ( n % 2 === 0 ) {
4395+ return str . slice ( mid - 1 , mid + 1 ) ;
4396+ } else {
4397+ return str [ mid ] ;
4398+ }
4399+ } ;
4400+
4401+ console . log ( foo ( str1 ) ) ;
4402+ console . log ( foo ( str2 ) ) ;
4403+
4404+ // 👍A) "r" "y" 💡B) "r" "ye"
4405+ // 💖C) "ra" "y" 😀D) "ra" "ye"
4406+
4407+ /*
4408+ Answer is B) "r" "ye" because the above code is to find the middle character of the word.
4409+ If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.
4410+ */
4411+ }
4412+ MCQ175 ( ) ;
You can’t perform that action at this time.
0 commit comments