Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
|||
let s = '9999';
|
||||
let splusplus = (+s+1)+""
|
||||
|
||||
console.log([splusplus, typeof splusplus]) // 10000,string
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// succString :: Bool -> String -> String
|
||||
const succString = blnPruned => s => {
|
||||
const go = w => {
|
||||
const
|
||||
v = w.includes('.') ? (
|
||||
parseFloat(w)
|
||||
) : parseInt(w);
|
||||
return isNaN(v) ? (
|
||||
blnPruned ? [] : [w]
|
||||
) : [(1 + v).toString()];
|
||||
};
|
||||
return unwords(concatMap(go, words(s)));
|
||||
};
|
||||
|
||||
// TEST -----------------------------------------------
|
||||
const main = () =>
|
||||
console.log(
|
||||
unlines(
|
||||
ap(
|
||||
map(succString, [true, false]),
|
||||
['41 pine martens in 1491.3 -1.5 mushrooms ≠ 136']
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// GENERIC FUNCTIONS ----------------------------------
|
||||
|
||||
// Each member of a list of functions applied to each
|
||||
// of a list of arguments, deriving a list of new values.
|
||||
|
||||
// ap (<*>) :: [(a -> b)] -> [a] -> [b]
|
||||
const ap = (fs, xs) => //
|
||||
fs.reduce((a, f) => a.concat(
|
||||
xs.reduce((a, x) => a.concat([f(x)]), [])
|
||||
), []);
|
||||
|
||||
// concatMap :: (a -> [b]) -> [a] -> [b]
|
||||
const concatMap = (f, xs) =>
|
||||
xs.reduce((a, x) => a.concat(f(x)), []);
|
||||
|
||||
// map :: (a -> b) -> [a] -> [b]
|
||||
const map = (f, xs) => xs.map(f);
|
||||
|
||||
// unlines :: [String] -> String
|
||||
const unlines = xs => xs.join('\n');
|
||||
|
||||
// unwords :: [String] -> String
|
||||
const unwords = xs => xs.join(' ');
|
||||
|
||||
// words :: String -> [String]
|
||||
const words = s => s.split(/\s+/);
|
||||
|
||||
// MAIN ---
|
||||
return main();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue