Skip to content

Instantly share code, notes, and snippets.

@on3dd
Last active January 29, 2021 03:58
Show Gist options
  • Save on3dd/2a550cd1e443043890aca8c4d40eb1b2 to your computer and use it in GitHub Desktop.
Save on3dd/2a550cd1e443043890aca8c4d40eb1b2 to your computer and use it in GitHub Desktop.
fp flavored solutions for https://youtu.be/XlI1zoH2gjU
const unriddle_me_1 = (str: string): string => {
const length = Math.ceil(str.length / 2);
const [a, b] = [str.slice(0, length), str.slice(length)];
return a.split('').reduce((acc, curr, idx) => {
return acc + curr + (b[idx] || '');
}, '');
};
console.log(
unriddle_me_1('Wligo ae n eeoigsfwrakn nwtraddvlpn otae'),
);
const unriddle_me_2 = (str: string): string => {
return str.split('').reduce((acc, curr, idx) => {
return idx % 2 ? acc : acc + curr;
}, '');
};
console.log(
unriddle_me_2(
'f rqofmv fa gstpheuc ikfuiyctaqtaixocnv fagrhey euaksiy',
),
);
const unriddle_me_3 = (str: string): string => {
return str
.slice(2)
.split('')
.reduce((acc, curr, idx) => {
return idx % 3 ? acc : acc + curr;
}, '');
};
console.log(
unriddle_me_3(
` gihjfkl oib 4o6jtaxhdb gha trh?e't r3fesrqqoa zs efgngy.`,
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment