jeanswqp.blogg.se

Slice js string
Slice js string








slice js string

So we can compose those functions to build our final getName function. The algorithm is: split by the colon and then get the first element of the given list. Let's build a first function: const first = (list) => list To get the first element we can use the list operator. Example: splitByTilde("john smith~123 Street~Apt 4~New York~NY~12345") // So now we can use our specialized splitByTilde function. We want to make this "john smith~123 Street~Apt 4~New York~NY~12345" into this const split = (separator) => (text) => text.split(separator)

slice js string

So the first thing would be the split function.

slice js string

This string.split("~") gets things done.Īnother functional approach using curry and function composition.










Slice js string