DEV Community

Discussion on: A coding interview question asked at Google

scott_yeatts profile image
Scott Yeatts • Edited on

Changed, only cause when I submitted on coderbyte, the test cases showed that "-B" cases were possible in the first string (IE: comparing vs an edited string as opposed to a base-string, so... egg on my face haha)

(And I edited again... because code review matters, and there's code to be removed...)

Here's the modified solution:

function compare(str) {
  return str.split(',')
    .reduce((agg, current) => {
      return current === '-B'
        ? agg.substring(0, agg.length - 1)
        : agg + current; 
    }, '');

function EquivalentKeypresses(strArr) { 

  // code goes here 
  return compare(strArr[0]).localeCompare(compare(strArr[1]),'en',{ignorePunctuation: true}) === 0;

// keep this function call here