function recursiveBinarySearch(arr, target, start = 0, end = arr.length - 1) {
if (start > end) {
return -1;
}
const mid = Math.floor((start + end) / 2);
if (arr[mid] === target) {
return mid;
} else if (arr[mid] < target) {
return recursiveBinarySearch(arr, target, mid + 1, end);
} else {
return recursiveBinarySearch(arr, target, start, mid - 1);
}
}
const result = recursiveBinarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9], 6);
console.log(result);
Please open Telegram to view this post
VIEW IN TELEGRAM
β€12π1
π€9π8 6π€£4β€3π€©2
Taking the manual, 'do it all by hand' approach. A good way to learn about all the pieces involved before automating it, perhaps.
SAM MEECH-WARD
Please open Telegram to view this post
VIEW IN TELEGRAM
β€9π4 2
function recursiveReverseString(str) {
return str === "" ? str : recursiveReverseString(str.substr(1)) + str[0];
}
const result = recursiveReverseString("hello");
console.log(result);
Please open Telegram to view this post
VIEW IN TELEGRAM
π€19π12 7β€6π€©4
const obj = {
0: 'a',
1: 'b',
length: 2
};
const result = Array.from(obj);
console.log(result);
Please open Telegram to view this post
VIEW IN TELEGRAM
What is the output?
Anonymous Quiz
32%
[βaβ, βbβ]
42%
[βaβ, βbβ, 2]
6%
[2, βaβ, βbβ]
20%
[0, 1, βlengthβ]
π€28β€10π7π€£6 6
Please open Telegram to view this post
VIEW IN TELEGRAM
π€26β€17 7π€©2
10K strong in under a year! β‘οΈ
Thanks to your incredible support, we're aiming for 100K next!π This isn't a dream β it's our plan in action! πͺ
Varik, Sipan, Nairi
βοΈ Check out our emoji pack here
βοΈ Boost us in Telegram
π€ Collaboration
Thanks to your incredible support, we're aiming for 100K next!
Varik, Sipan, Nairi
Please open Telegram to view this post
VIEW IN TELEGRAM
β€34π11 7π€©3π€2π€£1
Paul Scanlon compares React to Qwik using several examples and concludes that Qwik is at least worth exploring as a React alternative.
PAUL SCANLON
Please open Telegram to view this post
VIEW IN TELEGRAM
π5 5β€3
function* generatorQuiz() {
yield 1;
}
const generator = generatorQuiz();
setTimeout(() => console.log(generator.next().value), 0);
for (const value of generator) {
console.log(value);
}
Please open Telegram to view this post
VIEW IN TELEGRAM
function recursivePascalTriangle(n, row = [1], triangle = []) {
triangle.push(row);
if (n === triangle.length) {
return triangle;
}
const nextRow = [1];
for (let i = 1; i < row.length; i++) {
nextRow.push(row[i] + row[i - 1]);
}
nextRow.push(1);
return recursivePascalTriangle(n, nextRow, triangle);
}
const result = recursivePascalTriangle(5);
console.log(result);
Please open Telegram to view this post
VIEW IN TELEGRAM
π€9π2β€1π€£1 1
Help us get to know our diverse audience! Please select the region or country where you're currently located. Your input will assist us in tailoring our content to better suit your interests and preferences. Thank you for participating!
Anonymous Poll
8%
US
12%
Europe
6%
Arab countries
12%
Asian countries
15%
African countries
8%
Armenia
2%
Georgia
10%
Russia
2%
Brazil
25%
India
function recursiveNQueens(n) {
const board = Array.from({ length: n }, () => Array.from({ length: n }, () => "."));
const solutions = [];
const isSafe = (row, col) => {
for (let i = 0; i < row; i++) {
if (board[i][col] === "Q") return false;
const colOffset = row - i;
if (col - colOffset >= 0 && board[i][col - colOffset] === "Q") return false;
if (col + colOffset < n && board[i][col + colOffset] === "Q") return false;
}
return true;
};
const placeQueens = (row) => {
if (row === n) {
solutions.push(board.map(row => row.join("")));
return;
}
for (let col = 0; col < n; col++) {
if (isSafe(row, col)) {
board[row][col] = "Q";
placeQueens(row + 1);
board[row][col] = ".";
}
}
};
placeQueens(0);
return solutions;
}
const result = recursiveNQueens(4);
console.log(result);
Please open Telegram to view this post
VIEW IN TELEGRAM
β€2π1
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((acc, curr) => {
setTimeout(() => {
acc += curr;
}, 0);
return acc;
}, 0);
console.log(sum);
Please open Telegram to view this post
VIEW IN TELEGRAM
π8 6β€2
π€23π€£6 6β€3π2π€©1