Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const values = [1, 2, 3, 'a', 'b', 'c'];
- // [] -> []
- // [x] -> [x]
- // x: xs : y -> [x, y] ++ func(xs)
- const melder = values => {
- if (values.length <= 1) {
- return values;
- }
- const head = values[0];
- const tail = values[values.length - 1];
- const body = values.slice(1, values.length - 1);
- return [head, tail].concat(melder(body));
- };
- const res = melder(values);
- console.log('res', res);
Add Comment
Please, Sign In to add comment