javascript exercism io bob solution

Solutions on MaxInterview for javascript exercism io bob solution by the best coders in the world

showing results for - "javascript exercism io bob solution"
Rafaela
22 May 2019
1var Bob = function() {
2  return {
3    hey: function(input) {
4      // Remove leading or trailing spaces just in case.
5      input = input.trim();
6      
7      // Check for silence (empty string or spaces which would be removed by trim above).
8      if (input === '') {
9          return 'Fine. Be that way!';
10      }
11      
12      // Regular expression to test if there are any letter (alphabetic) characters
13      // in input string. (Regex excludes non-alpha characters.)
14      regex = /[^\W\d_]+/g;
15      
16      // Test for alpha characters and SHOUTING.
17      if (regex.test(input) && input === input.toUpperCase()) {
18        return 'Whoa, chill out!';
19      }
20      
21      // Check for a question.
22      if (input.charAt(input.length-1) === '?') {
23          return 'Sure.';
24      }
25      
26      // All other cases:
27      return 'Whatever.';
28    }
29  };
30};
31module.exports = Bob;