Skip to content

Instantly share code, notes, and snippets.

View jayrbolton's full-sized avatar
🍕

Jay R Bolton jayrbolton

🍕
View GitHub Profile
{- 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) {
{-
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
@jayrbolton
jayrbolton / stateful-dom
Last active October 15, 2019 22:17
state-based dom manipulation where dom elements get bound to special ui state objects
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
@jayrbolton
jayrbolton / Promises
Created June 10, 2015 19:12
Explanation of Promises
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
});