Question
/* QUESTION 3: The reverse function and Palindromes */ /* Implement reverse using recursion */ const reverse = (ls) => { /** **/ return undefined;
/* QUESTION 3: The reverse function and Palindromes */
/*
Implement reverse using recursion
*/
const reverse = (ls) => {
/**
return undefined;
/** **/
};
assert(reverse(ls).equals(List([5,4,3,2,1])));
/*
Implement reverse using fold_left
*/
const reverse2 = ls => /**
assert(reverse2(ls).equals(List([5,4,3,2,1])));
/*
Using map and your reverse function, write a function that takes
a list of strings and returns a list of pairs where each pair contains the
original string and true if it is a palindrome or false if it is not.
You may want to use the function reverse_str below in your implementation.
*/
const reverse_str = str => reverse(List(str.split(''))).join('');
assert(reverse_str("reverse") == "esrever");
const palindromes = ls => /**
const str_ls = List(["test", "testset"]);
const expected = List([List(["test", false]), List(["testset", true])]);
assert(palindromes(str_ls).equals(expected));
exports.ls_size = ls_size;
exports.sum_sqrs = sum_sqrs;
exports.avg_sqrs = avg_sqrs;
exports.ls_min = ls_min;
exports.ls_max = ls_max;
exports.ls_evens = ls_evens;
exports.ls_odds = ls_odds;
exports.max_even = max_even;
exports.min_even = min_even;
exports.reverse = reverse;
exports.reverse2 = reverse2;
exports.palindromes = palindromes;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started