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
@@ -1551,3 +1551,47 @@ console.log(numbers.reduce((total, num) => total + num));
1551
1551
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).
1552
1552
1553
1553
</details>
1554
+
1555
+
<details>
1556
+
<summary>
1557
+
<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>
1558
+
1559
+
_*You can't use built-in methods like filter or forEach._
1560
+
1561
+
</summary>
1562
+
1563
+
**Answer:**
1564
+
1565
+
Approach 1: Using a loop and conditional statement
1566
+
1567
+
```js
1568
+
functionfindEvenNumbers(numberArray) {
1569
+
constevenNumbers= [];
1570
+
for (let i =0; i <numberArray.length; i++) {
1571
+
if (numberArray[i] %2===0) {
1572
+
evenNumbers.push(numberArray[i]);
1573
+
}
1574
+
}
1575
+
return evenNumbers;
1576
+
}
1577
+
```
1578
+
1579
+
Approach 2: Using recursion and conditional statement
0 commit comments