This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let result = 0; | |
let arr = [1, 2, 5, 4, 6, 1, 2, 5, 4]; | |
for(let i = 0; i <= arr.length; i++){ | |
result = result ^ arr[i]; | |
} | |
console.log(" this is an unique number " + result); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reversedString (mystr) { | |
let str = ""; | |
for(let i = mystr.length; i > 0; i--){ | |
str += i; | |
} | |
return str; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reversedStringWihtBuildinFunc(str) { | |
return str.split("").reverse().join(""); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reverseString (str) { | |
if(str === "") return ""; else | |
return reverseString(str.substr(1)) + str.charAt(0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function swappingUsingTwoVars(num1, num2) { | |
num1 = num1 + num2; | |
num2 = num1 - num2; | |
num1 = num1 - num2; | |
return ("First number " + num1 + "\nSecond number " + num2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** | |
* @param {number} n | |
* @return {number} | |
*/ | |
var subtractProductAndSum = function(n) { | |
let num = n.toString().split(""); | |
let count = num.reduce((acc, sum)=>{ | |
acc += Number(sum); | |
return acc; | |
}, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** | |
* @param {number} n | |
* @return {number} | |
*/ | |
var subtractProductAndSum = function(n) { | |
let strNum = n.toString(); | |
let arr = strNum.split(""); | |
let mul = 1, count = 0; | |
for (let i = 0; i < arr.length; i++) { | |
mul *= arr[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var subtractProductAndSum = function(n) { | |
if (n / 10 == 0) | |
return 0; | |
let mul = 1, sum = 0; | |
while( n != 0) { | |
mul *= n % 10; | |
sum += n % 10; | |
n = Math.trunc(n / 10); | |
} | |
return mul - sum; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} x | |
* @return {boolean} | |
*/ | |
var isPalindrome = function(x) { | |
let str = ""; | |
let digit = x.toString(); | |
for(let i = digit.length - 1; i >= 0; i-- ) { | |
str += digit[i]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} x | |
* @return {boolean} | |
*/ | |
var isPalindrome = function(x) { | |
let sum = 0, n, m = x; | |
if (x < 0) return false; | |
while (x != 0 ) { | |
sum = sum * 10 + x % 10;; | |
x = Math.floor (x / 10); |
OlderNewer