-6

some one can help me , to solve this recursion , the question we must arrange the letter , if next letter not the sequence,it must be our output

function dataReducer(data) { 

}

console.log(dataReducer('abcdxefgh5wi')); // 'x,5,w'

console.log(dataReducer('opqrstu')); // ''

console.log(dataReducer('acdefghij')); // 'c,d,e,f,g,h,i,j'

console.log(dataReducer('testu')); // 'e,s,t'
Mathews Sunny
  • 1,796
  • 7
  • 21
  • 31
agny reza
  • 137
  • 2
  • 7
  • Welcome to Stack Overflow! Please take the [tour] and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) Do your research, [search](/help/searching) for related topics on SO, and give it a go. ***If*** you get stuck and can't get unstuck after doing more research and searching, post a [mcve] of your attempt and say specifically where you're stuck. People will be glad to help. Good luck! – T.J. Crowder Dec 16 '17 at 13:01
  • where do you see a purpose for a recusion? – Nina Scholz Dec 16 '17 at 15:06
  • @NinaScholz is recursion not *the* purpose itself? ~_^ – Mulan Dec 16 '17 at 23:23

1 Answers1

0

and totally redeem yourself !

SO likes to punish people if they don't show their work, but I'm not one to judge. I do think you will learn more if you try these problems on your own, but I know what it's like to be completely bewildered; and no good-natured soul amongst us wants to see you get stuck.

With that in mind, I really do think you can learn a lot from this answer. Please study it carefully and ask follow-up questions if you're confused.

const ord = c =>
  c.charCodeAt (0)

const isCharSeq = (x, y) =>
  ord (x) + 1 === ord (y)

const dataReducer = ([x, ...xs], last = null, acc = []) =>
  x === undefined
    ? acc.join (',')
  : last === null
    ? dataReducer (xs, x, acc)
  : isCharSeq (last, x)
    ? dataReducer (xs, x, acc)
  : dataReducer (xs, last, acc.concat ([x]))

console.log (dataReducer ('abcdxefgh5wi')) // 'x,5,w'
console.log (dataReducer ('opqrstu'))      // ''
console.log (dataReducer ('acdefghij'))    // 'c,d,e,f,g,h,i,j'
console.log (dataReducer ('testu'))        // 'e,s,t'
console.log (dataReducer ('a'))            // ''
console.log (dataReducer (''))             // ''

dataReducer is implemented with a proper tail call which means it can be optimised and even work on strings that are millions or billions of characters in length – even if JavaScript VM's never support this optimisation, don't worry, you can DIY.

Mulan
  • 129,518
  • 31
  • 228
  • 259
  • im so soory before , cause i really newbie(cause my backgorund before in metallurgy) , then want to become progammer , then im really thankfully , i will learn alot from your answer – agny reza Dec 18 '17 at 15:33
  • no need for apologies! if you have more questions, feel free to reach out. – Mulan Dec 18 '17 at 16:44