<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'))

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdn.jsdelivr.net/g/[email protected](lodash.min.js+lodash.fp.min.js)
  2. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js