<div id="root"></div>
// import some stuff from lodash
const { flow, split, head, tail, filter } = _
// this is just here to display results to DOM
const addResultToDOM = (...args) => $('#root').append(`<div>${args.join(' ')}</div>`)
const initialState = { counter: 0, timesClicked: 0 }
const getUserPath = flow(
split('?'), // splits string by ?, creates an array
head, // gets the first value
split('/'), // splits string by /, creates an array
tail, // gets all but first element of array
filter(v => v) // removes all empty strings and falsey values
)
getUserPath('/users/me?apiKey=foo')
addResultToDOM(`getUserPath('/users/me?apiKey=foo')`, getUserPath('/users/me?apiKey=foo'))
This Pen doesn't use any external CSS resources.