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
{- In Haskell, using lazy list comprehension -} | |
isPalindrome str = even (length str) && (take half str) == (reverse $ drop half str) | |
where half = length str `div` 2 | |
answer = maximum [x*y | x <- [100..999], y <- [100..999], (isPalindrome $ show (x*y))] | |
/* In JS, the imperative way */ | |
function isPalindrome(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
{- | |
In Haskell | |
-} | |
primeFactors n = recur 2 [] n | |
where | |
recur divisor facs limit | |
| divisor > limit = facs | |
| limit `mod` divisor == 0 = recur divisor (divisor:facs) (limit `div` divisor) | |
| otherwise = recur (divisor+1) facs limit |
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
The goals of this view library are: | |
- bridge the gap between js-land and html-land without mucking up the syntax and semantics of either | |
- little to no overhead to setup and use | |
- no precompilation, no transpiling, lightweight, fast | |
- declarative | |
- unit-testable UI behavior | |
The ideas: | |
- a lot like virtual-dom except more abstracted | |
- use plain JS objects and their regular JS semantics to define *view states* that affect the dom |
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
The primary way of interacting with a promise is through its `then` method, | |
which registers callbacks to receive either a promise's eventual value or the | |
reason why the promise cannot be fulfilled. | |
```js | |
findUser().then(function(user){ | |
// user is available | |
}, function(reason){ | |
// user is unavailable, and you are given the reason why | |
}); |
NewerOlder