Skip to main content
added 94 characters in body
Source Link
ndp
  • 2.4k
  • 1
  • 14
  • 9

Your code is concise and readable... I didn't have any feedback... it really shows how the functional solution is nicer.

I was curious if it could be done with regular expressions and no iteration, so I played around and got:

const numJewelsInStones = (j,s) => { 
  const m = s.match(new RegExp(`[${j}]`,'g'))
  return m ? m.length : 0 
}

or even

numJewelsInStones = (j,s) => s.replace(new RegExp(`[^${j}]`,'g'),'').length

Your code is concise and readable... I didn't have any feedback... it really shows how the functional solution is nicer.

I was curious if it could be done with regular expressions and no iteration, so I played around and got:

const numJewelsInStones = (j,s) => { 
  const m = s.match(new RegExp(`[${j}]`,'g'))
  return m ? m.length : 0 
}

Your code is concise and readable... I didn't have any feedback... it really shows how the functional solution is nicer.

I was curious if it could be done with regular expressions and no iteration, so I played around and got:

const numJewelsInStones = (j,s) => { 
  const m = s.match(new RegExp(`[${j}]`,'g'))
  return m ? m.length : 0 
}

or even

numJewelsInStones = (j,s) => s.replace(new RegExp(`[^${j}]`,'g'),'').length
Source Link
ndp
  • 2.4k
  • 1
  • 14
  • 9

Your code is concise and readable... I didn't have any feedback... it really shows how the functional solution is nicer.

I was curious if it could be done with regular expressions and no iteration, so I played around and got:

const numJewelsInStones = (j,s) => { 
  const m = s.match(new RegExp(`[${j}]`,'g'))
  return m ? m.length : 0 
}