Solution – 1 – Using Arithmetic Operators function swapNumb(a, b){ console.log('Before swap Output: ','a: ', a, 'b: ', b); b = b -a; a = a+ b; b = a-b; console.log('After swap Output: ','a: ', a, 'b: ', b); } swapNumb(2, 3); Solution – 2 – Using Bitwise XOR function …
Read More »Monthly Archives: September 2022
How to Create and get nth Fibonacci series number?
What is the Fibonacci series? Fibonacci series is the series of numbers that are calculated by adding the values of the previous two numbers in the sequence. The first two numbers of the sequence are zero and one. It is also known as the golden ratio. We can represent the …
Read More »Simple JavaScript code in promises.
function promiseExample(){ const promise = new Promise((resolve, reject) =>{ resolve('successfully!'); }) .then((resolve) => console.log(resolve)) .catch((reject) => console.log(reject)); return promise; } promiseExample() I have a create simple code example for promises. you can easily check. how to resolve is working? and how to reject is working?
Read More »How to fetch API Data from API in React Using useEffect?
import React, { useState, useEffect } from "react"; // Use can use css from this file: import "./styles.css"; const url = "https://jsonplaceholder.typicode.com/posts"; function App() { const [userData, setUserData] = useState({}); const getUserData = async () => { const response = await fetch(url); const jsonData = await response.json(); setUserData(jsonData); }; useEffect(() …
Read More »You are given a two-digit integer n. Return the sum of its digits.
You are given a two-digit integer n. Return the sum of its digits. Example For n = 29, the output should be solution(n) = 11. Input/Output [execution time limit] 4 seconds (js) [input] integer n A positive two-digit integer. Guaranteed constraints: 10 ≤ n ≤ 99. [output] integer The sum …
Read More »Given an array of integers a, your task is to count the number of pairs i and j (where 0 ≤ i < j < a.length), such that a[i] and a[j] are digit anagrams.
Given an array of integers a, your task is to count the number of pairs i and j (where 0 ≤ i < j < a.length), such that a[i] and a[j] are digit anagrams. Two integers are considered to be digit anagrams if they contain the same digits. In other …
Read More »