This file contains hidden or 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
| change n | n < minimum coins = [[]] | |
| | otherwise = [xs | x <- coins, | |
| x <= n, | |
| xs <- map (\ys -> x:ys) $ change (n - x), | |
| sum xs == n] |
This file contains hidden or 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 clockAngle = function (h, m) { | |
| return Math.abs((h * 30 + m * 0.5) - (m * 6)); | |
| } |
This file contains hidden or 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 checkPhoneNumberFormat = function (phone) { | |
| return /^[ ()\-0-9]+$/.test(str); | |
| } |
This file contains hidden or 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 checkAnagram = function(word1, word2) { | |
| if (word1 == "" || word2 == "") return false; | |
| word1 = word1.split('').sort(); | |
| word2 = word2.split('').sort(); | |
| if (word1.length != word2.length) { | |
| return false; | |
| } | |
| for (var i = 0; i < word1.length; i++) { | |
| if (word1[i] != word2[i]) { | |
| return false; |
This file contains hidden or 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 isCorrectParentheses = function (str) { | |
| var i = 0; | |
| for (var ch = 0; ch < str.length; ch++) { | |
| if (str[ch] === '(') i++; | |
| if (str[ch] === ')') i--; | |
| if (i < 0) return false; | |
| } | |
| if (i !== 0) return false; | |
| return true; | |
| } |
This file contains hidden or 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 moveZerosTest = function (arr) { | |
| var arr2 = [] | |
| var zeroCount = 0; | |
| var counter = 0; | |
| for (var i = 0; i < arr.length; i++) { | |
| if (arr[i] === 0) { | |
| zeroCount += 1; | |
| } else { | |
| arr2[counter] = arr[i]; | |
| counter++; |
This file contains hidden or 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 isValidCreditCard = function (xs) { | |
| return xs.split('').reverse().map(function (elem, index, xs) { | |
| return index % 2 ? (2 * elem < 9 ? 2 * elem : 2 * elem - 9) : Number(elem); | |
| }).reduce(function(sum, elem) { return sum + elem }) % 10 == 0; | |
| } |
This file contains hidden or 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 difference = function (x) { | |
| var sumSq = 0, | |
| sqSum = 0; | |
| for (var i = 1; i <= x; i++) { | |
| sumSq += i * i; | |
| sqSum += i | |
| } | |
| return sqSum * sqSum - sumSq | |
| } |
This file contains hidden or 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 transpose = function (matrix) { | |
| var result = []; | |
| for (var i = 0; i < matrix.length; i++) { | |
| for (var j = 0; j < matrix[i].length; j++) { | |
| if (result[j] == undefined) result[j] = []; | |
| result[j][i] = matrix[i][j]; | |
| } | |
| } | |
| return result | |
| } |
This file contains hidden or 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 isPrime = function (n) { | |
| for (var i = 2; i < n; i++) { | |
| if (n % i == 0) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| var sumPrimes = function (x) { | |
| var result = 0; |
OlderNewer