Skip to content

Commit ca843a4

Browse files
committed
Guess The Output? - 175
1 parent 7c5eaf8 commit ca843a4

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

Guess-The-Output.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)