Created
January 15, 2018 09:30
-
-
Save dreamline2/17b5ef3202fad0933ffcd759d04ba730 to your computer and use it in GitHub Desktop.
ezprice_interview_question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://leetcode.com/problems/basic-calculator/description/ | |
var calculate = function(s) { | |
var positiveArr = s.replace(/\s|\(|\)|\-\d{1}/g,"").split(/\+/); | |
var positiveNum = positiveArr.reduce( (x,y) => parseInt(x) + parseInt(y) ); | |
var hasNegative = s.replace(/\s|\(|\)/g,"").replace(/^\d{1}|\+\d{1}/g, ""); | |
var negativeNum, negativeArr; | |
if (hasNegative) { | |
negativeArr = hasNegative.split(/\-/).filter(x=>x); | |
negativeNum = parseInt(negativeArr.reduce( (x,y) => parseInt(x) + parseInt(y) )); | |
} else { | |
negativeNum = 0; | |
}; | |
return positiveNum - negativeNum; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://leetcode.com/problems/regular-expression-matching/description/ | |
var isMatch = function(s, p) { | |
const re = new RegExp(p); | |
const supportRe = new RegExp(/\.|\*/); | |
if (supportRe.test(p)) { | |
return re.test(s); | |
} else { | |
return s == p; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment