Check out example codes for "code wars responsable drinker". It will help you in understanding the concepts better.

Code Example 1

function hydrate(s) {
   let waterCount = s.split('').filter(e => e.match(/\d/)).reduce((acc, val) => +acc + +val, 0);
  return waterCount > 1 ? `${waterCount} glasses of water`: `${waterCount} glass of water`;
}

Learn ReactJs, React Native from akashmittal.com