Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const bq1 = node('blockquote', 'quote');
- const bq2 = node('p', 'another quote');
- const processedHtml = map(element => {
- if( is('blockquote', element)) {
- return node('p', value(element));
- }
- return element;
- }, append(append(make(), bq1), bq2));
- export const map = (func, elements) => {
- if (isEmpty(elements)) {
- return l();
- }
- const newElement = func(head(elements);
- return cons(newElement, map(func, tail(elements)));
- }
- export const filter = (func, elements) => {
- if (isEmpty(elements)) {
- return l();
- }
- const current = head(elements);
- const tailElements = tail(elements);
- if (func(current)) {
- return cons(current, filter(func, tailElements);
- }
- return filter(func, tailElements);
- };
- ///итеративно!
- export const filter = (func, elements) => {
- const iter = (dom, acc) => {
- if (isEmpty(dom)) {
- return acc;
- }
- const current = head(dom);
- const tailElements = tail(dom);
- if (func(current)) {
- return iter(tailElements, cons(current, acc));
- }
- return iter(tailElements, acc);
- }
- return reverse(iter(elements, l()));
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement