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
// This is an example of how cooperative multitasking could be | |
// emulated in Javascript. | |
// Javascript has only generators, which are "half-coroutines", | |
// meaning they can only yield to their called and not other | |
// generators. We can add a special "coordinator" generator and | |
// a yielding convention to make it look almost exactly like | |
// we have full coroutines. | |
// Note that the yield* operator is not what we need here. |
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
// https://github.com/yankouskia/love-triangle | |
module.exports = function getLoveTrianglesCount(preferences = []) { | |
return ( | |
preferences.map((x, i) => getTriangle(preferences, i)).filter(x => x) | |
.length / 3 | |
); | |
}; | |
const getTriangle = (preferences, index) => { | |
if (preferences[index] - 1 == index) { |
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
(ns clojure-noob.core | |
(:gen-class)) | |
(defn parse [url] | |
(println url) | |
(org.jsoup.Jsoup/parse (slurp url))) | |
(defn href [a] (.attr a "href")) | |
(defn fetch [a] (parse (href a))) |