Not the fastest algorithm but this is what I came up with.
"use strict"; const normalize = (xs, x) => x === "-B" ? xs.slice(0, -1) : [...xs, x]; const checkEquivalentKeypresses = ([xs, ys]) => xs.split(",").reduce(normalize, []).join(",") === ys.split(",").reduce(normalize, []).join(",") console.log(checkEquivalentKeypresses(["a,b,c,d", "a,b,c,c,-B,d"])); // true console.log(checkEquivalentKeypresses(["-B,-B,-B,c,c", "c,c"])); // true console.log(checkEquivalentKeypresses(["", "a,-B,-B,a,-B,a,b,c,c,c,d"])); // false
Good work!
I like this solution as it is very straight forward. Defining normalize was great going in.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Not the fastest algorithm but this is what I came up with.
Good work!
I like this solution as it is very straight forward. Defining normalize was great going in.