Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
|||
function stripComments(s) {
|
||||
var re1 = /^\s+|\s+$/g; // Strip leading and trailing spaces
|
||||
var re2 = /\s*[#;].+$/g; // Strip everything after # or ; to the end of the line, including preceding spaces
|
||||
return s.replace(re1,'').replace(re2,'');
|
||||
}
|
||||
|
||||
|
||||
var s1 = 'apples, pears # and bananas';
|
||||
var s2 = 'apples, pears ; and bananas';
|
||||
|
||||
alert(stripComments(s1) + '\n' + stripComments(s2));
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
var stripComments = (function () {
|
||||
var re1 = /^\s+|\s+$/g;
|
||||
var re2 = /\s*[#;].+$/g;
|
||||
return function (s) {
|
||||
return s.replace(re1,'').replace(re2,'');
|
||||
};
|
||||
}());
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
const main = () => {
|
||||
|
||||
const src = `apples, pears # and bananas
|
||||
apples, pears ; and bananas`;
|
||||
|
||||
return unlines(
|
||||
map(preComment(chars(';#')),
|
||||
lines(src)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
// preComment :: [Char] -> String -> String
|
||||
const preComment = cs => s =>
|
||||
strip(
|
||||
takeWhile(
|
||||
curry(flip(notElem))(cs),
|
||||
s
|
||||
)
|
||||
);
|
||||
|
||||
// GENERIC FUNCTIONS ------------------------------
|
||||
|
||||
// chars :: String -> [Char]
|
||||
const chars = s => s.split('');
|
||||
|
||||
// curry :: ((a, b) -> c) -> a -> b -> c
|
||||
const curry = f => a => b => f(a, b);
|
||||
|
||||
// flip :: (a -> b -> c) -> b -> a -> c
|
||||
const flip = f => (a, b) => f.apply(null, [b, a]);
|
||||
|
||||
// lines :: String -> [String]
|
||||
const lines = s => s.split(/[\r\n]/);
|
||||
|
||||
// map :: (a -> b) -> [a] -> [b]
|
||||
const map = (f, xs) => xs.map(f);
|
||||
|
||||
// notElem :: Eq a => a -> [a] -> Bool
|
||||
const notElem = (x, xs) => -1 === xs.indexOf(x);
|
||||
|
||||
// strip :: String -> String
|
||||
const strip = s => s.trim();
|
||||
|
||||
// takeWhile :: (a -> Bool) -> [a] -> [a]
|
||||
// takeWhile :: (Char -> Bool) -> String -> String
|
||||
const takeWhile = (p, xs) => {
|
||||
let i = 0;
|
||||
const lng = xs.length;
|
||||
while ((i < lng) && p(xs[i]))(i = i + 1);
|
||||
return xs.slice(0, i);
|
||||
};
|
||||
|
||||
// unlines :: [String] -> String
|
||||
const unlines = xs => xs.join('\n');
|
||||
|
||||
// MAIN ---
|
||||
return main();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue