Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Last active June 9, 2017 11:17
Show Gist options
  • Save Woodsphreaker/9a552b82a4d71ac7f37466b4935ba97b to your computer and use it in GitHub Desktop.
Save Woodsphreaker/9a552b82a4d71ac7f37466b4935ba97b to your computer and use it in GitHub Desktop.
Merging Strings with Matrix
const plus = (a = '') => (b = '') => a + b
const applyOperation = (fn) => (acc, cur) => acc.map((value, index) => fn(cur[index])(value))
const matrix = (list) => (fn) => list.reduceRight(applyOperation(fn))
const solve = (list) => (fn) => matrix(list)(fn).join('')
const str1 = "Testando".split('')
const str2 = "String".split('')
const str3 = "de".split('')
const str4 = "Varios".split('')
const str5 = "Tamanhos".split('')
const array = [
str1,
str2,
str3,
str4,
str5
]
console.log(solve(array)(plus)) //TSdVTeteaasrrmtiiaanonngshdoos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment