From 27ae17bacd8fd26f9a0ba00af70fe10b41f6b424 Mon Sep 17 00:00:00 2001 From: Mayank Yadav Date: Thu, 2 Mar 2017 16:40:11 +0530 Subject: [PATCH] edgecase sizeType validation fix sizeType validation does not work for inputs that start with number and are followed by string. --- excercises/2-props/solution.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/excercises/2-props/solution.js b/excercises/2-props/solution.js index 1163190..aec33f4 100644 --- a/excercises/2-props/solution.js +++ b/excercises/2-props/solution.js @@ -17,9 +17,22 @@ var emailType = (props, propName, componentName) => { ); }; +function validateSize(inputValue) { + if (Number.isInteger(inputValue)) { + return true; + } + + if (typeof inputValue === 'string') { + let number = parseInt(inputValue); + return ((number + "") === inputValue); + } + + return false; +} + var sizeType = (props, propName, componentName) => { warning( - !isNaN(parseInt(props[propName])), + validateSize(props.size), `Invalid prop "${propName}", can't convert "${props[propName]}" to number. Check the render method of "${componentName}".` ); };