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 findMissingNumber = function (arr) { | |
var step = (arr[arr.length - 1] - arr[0]) / (arr.length) | |
for (var i = 0; i < arr.length; i++) { | |
if (arr[i] != arr[0] + step * i) { | |
return arr[0] + step * 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 supremumSyracuse = function (num) { | |
var sequence = []; | |
while ((num = num % 2 ? num * 3 + 1 : Math.floor(num / 2)) !== 1) { | |
sequence[sequence.length] = num; | |
} | |
return sequence.sort(function (a, b) { | |
return a - b; | |
})[sequence.length - 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
var areDisjoint = function (arr1, arr2) { | |
var tmp = arr1.concat(arr2).sort(function (a, b) { | |
return a - b; | |
}); | |
for (var i = 1; i < tmp.length; i++) { | |
if (tmp[i - 1] == tmp[i]) { | |
return false; | |
} | |
} | |
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
String.prototype.replace = function(search, replace){ | |
return this.split(search).join(replace); | |
} | |
var wordPattern = function (p, s) { | |
var temp0 = p.split(''); | |
var temp1 = s.split(' '); | |
var temp2 = {}; | |
for (var i = 0; i < temp0.length; i++) { | |
if (temp2[temp0[i]] == undefined) { |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test Select form Matreshka</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<link href="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" /> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script> | |
<script src="http://cdn.jsdelivr.net/matreshka/latest/matreshka.min.js"></script> | |
</head> | |
<body> |
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
import Data.Char | |
import Data.List | |
readDigits :: String -> (String, String) | |
readDigits = span isDigit | |
filterDisj :: (a -> Bool) -> (a -> Bool) -> [a] -> [a] | |
filterDisj f g = filter (\x -> f x || g x) | |
qsort :: Ord a => [a] -> [a] |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test Select form Matreshka</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<link href="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" /> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script> | |
<script src="http://cdn.jsdelivr.net/matreshka/latest/matreshka.min.js"></script> | |
</head> | |
<body> |
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 titleToNumber = function (str) { | |
var result = 0; | |
str.split('').reverse().forEach(function (ch, index) { | |
result += (ch.charCodeAt(0) - 64) * Math.pow(26, index); | |
}); | |
return 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
import Data.Char(isDigit) | |
data Error = ParsingError | IncompleteDataError | IncorrectDataError String | |
deriving (Show) | |
data Person = Person { firstName :: String, lastName :: String, age :: Int } | |
deriving (Show) | |
split delimiter = foldr f [[]] | |
where f c l@(x:xs) | c == delimiter = []:l |
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
import Prelude hiding (lookup) | |
import qualified Data.List as L | |
class MapLike m where | |
empty :: m k v | |
lookup :: Ord k => k -> m k v -> Maybe v | |
insert :: Ord k => k -> v -> m k v -> m k v | |
delete :: Ord k => k -> m k v -> m k v | |
fromList :: Ord k => [(k,v)] -> m k v | |
fromList [] = empty |