Write a function of type String -> Integer
. The input may or may not be a
valid JSON string. If it is valid, the resulting JavaScript value is expected
to be an object, but may not be. If it is an object, it is expected to have a
foo
property whose value is expected to be an object, but may not be. This
value is expected to have a bar
property which is expected to be an object
with a baz
property whose value is expected to be an array of strings.
Each of these strings is expected to be a hex representation of an integer
(e.g. 0xFF
). If every element of the array meets this expectation, the
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 {deepStrictEqual as eq} from "node:assert"; | |
// class ListLike f where | |
// empty :: f a | |
// cons :: a -> f a -> f a | |
// fold :: f a -> b -> (b -> a -> b) -> b | |
// map :: f a -> (a -> b) -> f b | |
// length :: f a -> Int | |
const Array = { |
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 S from 'sanctuary'; | |
import Identity from 'sanctuary-identity'; | |
// lens :: (s -> a) -> (a -> s -> s) -> Lens s a | |
const lens = getter => setter => f => s => ( | |
S.map (v => setter (v) (s)) | |
(f (getter (s))) | |
); |
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
//# zip :: Array a -> Array a -> Array a | |
//. | |
//. Zip two arrays, xs and ys, of arbitrary lengths. | |
//. | |
//. let n = Math.min (xs.length, ys.length); | |
//. | |
//. If the first array is longer than the second, the result will | |
//. consist of the first n + 1 elements of the first array and | |
//. all n elements of the second array. Otherwise, the result will | |
//. consist of the first n elements of each array. |
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
//# groupBy :: (a -> b) -> Array a -> Array (Array a) | |
//. | |
//. Group the given elements in accordance with the given comparator. | |
//. | |
//. > groupBy (x => x % 3) ([1, 2, 3, 4, 5, 6, 7, 8, 9]) | |
//. [[1, 4, 7], [2, 5, 8], [3, 6, 9]] | |
const groupBy = f => xs => { | |
const groups = []; | |
const ys = []; | |
xs.forEach (x => { |
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
'use strict'; | |
const Future = require ('fluture'); | |
const S = require ('sanctuary'); | |
// data Action = Reset | Increment Integer | Decrement Integer | |
// Reset :: Action | |
const Reset = {tagName: 'Reset'}; |
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
'use strict'; | |
const R = require('ramda'); | |
const S = require('sanctuary'); | |
const data = { | |
id: 1, | |
orderName: 'Order from spain', | |
teamName: 'Portland penguins', |
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 file demonstrates a simpler approach to the problem posed in | |
// <https://gist.github.com/kurtmilam/ff453e13225580f098d1f64f4bc3e9c7>. | |
// | |
// Note that it's possible to define a parametrically polymorphic `move` | |
// function by using a `Shape s` constraint. On the other hand it is not | |
// possible to define a parametrically polymorphic `area` function since | |
// circles and rectangles require different logic. | |
// | |
// One could solve this problem by defining a type representative for each | |
// shape type, which would provide a suitable `area` function (`Z.of` takes |
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
function drop(n) { | |
s = "" | |
for (i = n + 1; i <= NF; i += 1) { s = s (s == "" ? "" : " ") $i } | |
return s | |
} | |
/^ *\/\/\. ##/ { | |
indent = substr($2, 2) # reduce indentation by one level | |
gsub(/#/, " ", indent) | |
href = tolower(drop(2)) |
var convertPercentage = function(percentage) { if (percentage == null) { return null; } else { return parseFloat(percentage.replace(/[^-\d.]/g, '')); } };
NewerOlder