You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<spanstyle="font-size: 1rem; border-bottom: 1pxsolidgrey;"> Updated Jan 07, 2024 </span>
7
+
<spanstyle="font-size: 1rem; border-bottom: 1pxsolidgrey;"> Updated Mar 31, 2024 </span>
8
8
9
9
In this article, we will cover a range of JavaScript interview questions, including those related to the latest versions of the language (ES6, ES7, ES8, and ES9).
10
10
@@ -1549,3 +1549,47 @@ console.log(numbers.reduce((total, num) => total + num));
1549
1549
4. **Output:** The final `console.log()` statement outputs the result of the `reduce()` operation, which is 30 (the sum of all the doubled numbers in the array).
1550
1550
1551
1551
</details>
1552
+
1553
+
<details>
1554
+
<summary>
1555
+
<h3>47. Write a JavaScript function that takes an array of numbers as input and returns a new array containing only the even numbers.</h3>
1556
+
1557
+
_*You can't use built-in methods like filter or forEach._
1558
+
1559
+
</summary>
1560
+
1561
+
**Answer:**
1562
+
1563
+
Approach 1: Using a loop and conditional statement
1564
+
1565
+
```js
1566
+
functionfindEvenNumbers(numberArray) {
1567
+
constevenNumbers= [];
1568
+
for (let i =0; i <numberArray.length; i++) {
1569
+
if (numberArray[i] %2===0) {
1570
+
evenNumbers.push(numberArray[i]);
1571
+
}
1572
+
}
1573
+
return evenNumbers;
1574
+
}
1575
+
```
1576
+
1577
+
Approach 2: Using recursion and conditional statement
0 commit comments