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 findEvenIndex(arr) | |
{ | |
var left = 0, right = arr.reduce(function(pv, cv) { return pv + cv; }, 0); | |
for(var i = 0; i < arr.length; i++) { | |
if(i > 0) left += arr[i-1]; | |
right -= arr[i]; | |
if(left == right) return 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
function listSquared (m, n) { | |
var matches = []; | |
for (var i = m; i <= n; ++i) { | |
var sum = getDivisors(i).reduce((sum, n) => sum + n * n, 0); | |
var ok = Number.isInteger(Math.sqrt(sum)); | |
if (ok) { | |
matches.push([i, 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
var sum_pairs=function(ints, s){ | |
var arr = []; | |
for(var i = 0; i < ints.length; i++) { | |
for(var j = 0; j < ints.length; j++) { | |
if(ints[i] + ints[j] === s && j !== i) { | |
arr.push(ints[i],ints[j]); | |
return 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 isPangram(string){ | |
string = string.toLowerCase(); | |
return "abcdefghijklmnopqrstuvwxyz".split("").every(function(x){ | |
return string.indexOf(x) !== -1; | |
}); | |
} |
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
arr.forEach(function(x) { counts[x] = (counts[x] || 0)+1; }); |
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 validate(password) { | |
return /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$/.test(password); | |
} //alphanumeric, one lowercase, one uppercase, one number, 6 or greater length |
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 validatePIN(pin) { | |
return /^(\d{4}|\d{6})$/.test(pin) | |
} |
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 listToArray(list) { | |
var array = []; | |
for (var node = list; node; node = node.next) | |
array.push(node.value); | |
return array; | |
} |
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 SeriesSum(n) { | |
for (var s = 0, i = 0; i < n; i++) { | |
s += 1 / (1 + i * 3) | |
} | |
return s.toFixed(2) | |
} |
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 sumTwoSmallestNumbers(numbers){ | |
numbers = numbers.sort(function(a, b){return a - b; }); | |
return numbers[0] + numbers[1]; | |
}; |