Can You Find Consecutive Tiny Words in a Sentence?
JS Bytes Issue #1 - Become a better JS Engineer
As promised I am here with the first issue of JS Bytes.
Improve your JavaScript byte by byte.
Problem Solving Challenge
In this section, you'll find a unique challenge designed to test your problem-solving skills. Can you think like a programmer and solve it?
Detecting Consecutive Tiny Words
Description:
There’s a common guideline in writing: avoid sequences of tiny words. This means that if a sentence contains three or more consecutive two-letter words, it's considered to have too many tiny words.
Your task is to write a JavaScript function that checks if a given sentence contains a sequence of three or more consecutive two-letter words.
Function Signature:
function hasTinyWordChunk(sentence) {
// write your logic below this line
return false
}
// Test cases
console.log(hasTinyWordChunk('Please go to the store and do it quickly.')) // false
console.log(hasTinyWordChunk('It is so great to finally meet you in person.')) // true
console.log(hasTinyWordChunk('I am so glad that you can go now and enjoy the event.')) // false
console.log(hasTinyWordChunk('He is at it by himself, trying to fix up the car.')) // true
Example Sentences:
"Please go to the store and do it quickly."
"It is so great to finally meet you in person."
"I am so glad that you can go now and enjoy the event."
"He is at it by himself, trying to fix up the car."
Expected Output:
false
(no three consecutive two-letter words)true
(because"It is so"
has three consecutive two-letter words)false
(no three consecutive two-letter words)true
(because"is at it"
has three consecutive two-letter words)
3 Conceptual MCQs
This section includes three conceptual JavaScript multiple-choice questions to test your understanding of JavaScript concepts.
Instructions:
Dry run the code in your brain, no editor or terminal allowed. Once you've answered, test the code in your browser console or editor to check your answers.
1. What will be the output of the following code?
const colors = ['red', 'blue', 'green'];
const favColors = colors;
favColors[1] = 'purple';
console.log(colors === favColors);
console.log(colors);
A) true
, ['red', 'blue', 'green']
B) true
, ['red', 'purple', 'green']
C) false
, ['red', 'purple', 'green']
D) false
, ['red', 'blue', 'green']
If this issue helped you improve your JavaScript skills, please share it with other developers! Feel free to connect with me on LinkedIn and share your thoughts.
2. What will be the output of the following code?
const user = {
name: 'Ahmed',
email: 'ahmed@email.com',
designation: 'Frontend Developer',
address: { city: 'Karachi' },
}
const newUser = { ...user, designation: 'Fullstack Engineer' }
newUser.address.city = 'Lahore'
console.log(user.address.city)
console.log(newUser)
A)
Lahore
,{ name: 'Ahmed', email: 'ahmed@email.com', designation: 'Fullstack Engineer', address: { city: 'Lahore' } }
B)
Karachi
,{ name: 'Ahmed', email: 'ahmed@email.com', designation: 'Fullstack Engineer', address: { city: 'Lahore' } }
C)
Karachi
,{ name: 'Ahmed', email: 'ahmed@email.com', designation: 'Fullstack Engineer', address: { city: 'Karachi' } }
D)
Lahore
,{ name: 'Ahmed', email: 'ahmed@email.com', designation: 'Fullstack Engineer', address: { city: 'Karachi' } }
3. What will be the output?
var a = 10
{
var a = 20
console.log(a) // Output 1
}
console.log(a) // Output 2
let b = 30
{
let b = 40
console.log(b) // Output 3
}
console.log(b) // Output 4
const c = 50
try {
c = 60
} catch (e) {
console.log(e.message) // Output 5
}
console.log(c) // Output 6
A)
10
,20
,30
,40
,60
,50
B)
20
,10
,40
,30
,"Assignment to constant variable."
,50
C)
20
,20
,40
,30
,"Assignment to constant variable."
,50
D)
20
,10
,SyntaxError: Identifier 'b' has already been declared
,TypeError: Assignment to constant variable
Feel free to connect with me on LinkedIn and share your thoughts.