Humble numbers: Difference between revisions

Content added Content deleted
(→‎{{header|JavaScript}}: updated primitives)
Line 1,959: Line 1,959:
) : v;
) : v;
};
};



// justifyRight :: Int -> Char -> String -> String
// justifyRight :: Int -> Char -> String -> String
Line 1,968: Line 1,969:
) : s;
) : s;


// Returns Infinity over objects without finite length.
// This enables zip and zipWith to choose the shorter
// argument when one is non-finite, like cycle, repeat etc


// length :: [a] -> Int
// length :: [a] -> Int
const length = xs =>
const length = xs =>
// Returns Infinity over objects without finite length.
// This enables zip and zipWith to choose the shorter
// argument when one is non-finite, like cycle, repeat etc
(Array.isArray(xs) || 'string' === typeof xs) ? (
(Array.isArray(xs) || 'string' === typeof xs) ? (
xs.length
xs.length
Line 1,994: Line 1,995:
// (The image of xs under f).
// (The image of xs under f).
xs => [...xs].map(f);
xs => [...xs].map(f);



// str :: a -> String
// str :: a -> String
const str = x => x.toString();
const str = x =>
x.toString();



// take :: Int -> [a] -> [a]
// take :: Int -> [a] -> [a]
Line 2,009: Line 2,013:
return x.done ? [] : [x.value];
return x.done ? [] : [x.value];
}));
}));



// takeWhileGen :: (a -> Bool) -> Gen [a] -> [a]
// takeWhileGen :: (a -> Bool) -> Gen [a] -> [a]
Line 2,023: Line 2,028:
return ys;
return ys;
};
};



// zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
// zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]