DEV Community

Discussion on: Functional style programming is awesome (isomorphic example)

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited
const structure = s => [...s].map(c => s.indexOf(c)).join('')
Enter fullscreen mode Exit fullscreen mode

There's actually a very obvious mistake in that implementation: what if the index reaches 10?

The strings abcdefghijk and abcdefghijba are equal according to your structure function 😉

Collapse
 
jefftian profile image
Jeff

Wow that's quite a flaw! I've fixed in github.com/Jeff-Tian/JobInterviewT..., by change the structure to const structure = s => [...s].map(c => s.indexOf(c)).join('-'). And I've added your test case(github.com/Jeff-Tian/JobInterviewT...), that's awesome, thanks a ton!