Skip to content

Instantly share code, notes, and snippets.

@edwinestrada
Last active June 26, 2017 23:21
Show Gist options
  • Save edwinestrada/4702cecd612625c3fc0d0f08893a3162 to your computer and use it in GitHub Desktop.
Save edwinestrada/4702cecd612625c3fc0d0f08893a3162 to your computer and use it in GitHub Desktop.
Programming Challenges 1-3

Challenge 1

combineStrings = () => {
  let a = 'super';
  let b = '12345';
  let output = a + ' + ' + b + ' =';
  // output += a ? a.map(letter => ) : null;
  if(a && b) {
    output += a.split('').map(function(l, i) {
      return l + b.slice(i, i+1);
    }).join('');
    if(b.length > a.length) {
      output += b.slice(a.length);
    }
  }
  return output;
}

Challenge 2

function stringContainsWord(s, word, wordCount = 0) {
  if(s.indexOf(word) >= 0) {
    let foundAtIndex = s.search(word);
    let shorterString = s.slice(foundAtIndex + word.length);
    return this.stringContainsWord(shorterString, word, ++wordCount);
  } else {
    return wordCount;
  }
}

stringContainsWord('swordfishtrombonesbabyfishmouth', 'fish');

Challenge 3

SELECT Id, Summary, NewStatus
FROM Tickets
INNER JOIN (
  SELECT TicketId, NewStatus, MAX(Timestamp) as maxTimestamp
  FROM StatusChanges
  GROUP BY TicketId
) tm ON Tickets.Id=tm.TicketId
WHERE NOT NewStatus='Closed';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment