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 removeDuplicate(arr) { | |
return arr.filter((element, index, array) => array.indexOf(element) === index); | |
} |
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 removeDuplicate(arr) { | |
return Array.from(new Set(arr)) | |
} |
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 reverse(str){ | |
var rtnStr = []; | |
if(!str || typeof str != 'string' || str.length < 2 ) return str; | |
for(var i = str.length-1; i>=0;i--){ | |
rtnStr.push(str[i]); | |
} | |
return rtnStr.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 reverse (str) { | |
if (str === "") { | |
return ""; | |
} else { | |
return reverse(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 missingNumber(arr){ | |
var n = arr.length+1, | |
sum = 0, | |
expectedSum = n* (n+1)/2; | |
sum = arr.reduce((total, num) => total + num); | |
return expectedSum - sum; | |
} | |
missingNumber([5, 2, 6, 1, 3]); |
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 permut(string) { | |
if (string.length < 2) return string; // This is our break condition | |
var permutations = []; // This array will hold our permutations | |
for (var i=0; i<string.length; i++) { | |
var char = string[i]; | |
// Cause we don't want any duplicates: | |
if (string.indexOf(char) != i) // if char was used already |
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 sumFinder(arr, sum){ | |
var len = arr.length; | |
for(var i =0; i<len-1; i++){ | |
for(var j = i+1;j<len; j++){ | |
if (arr[i] + arr[j] == sum) | |
return true; | |
} | |
} | |
return false; |
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 sumFinder(arr, sum){ | |
var differ = {}, | |
len = arr.length, | |
substract; | |
for(var i =0; i<len; i++){ | |
substract = sum - arr[i]; | |
if(differ[substract]) | |
return true; |
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 isBalanced(str) { | |
var i, ch; | |
var bracketsMap = new Map(); | |
bracketsMap.set(']', '['); | |
bracketsMap.set('}', '{'); | |
bracketsMap.set(')', '('); | |
// Use the spread operator to transform a map into a 2D key-value Array. | |
var closingBrackets = [...bracketsMap.keys()]; |
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
// ❌ | |
asyncFunc1((err, result1) => { | |
asyncFunc2(result1, (err, result2) => { | |
asyncFunc3(result2, (err, result3) => { | |
console.log(result3) | |
}) | |
}) | |
}) | |
// ✔️ |
OlderNewer