-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alessandro Giordo
committed
Feb 8, 2016
1 parent
a6b55c0
commit 11e2a70
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function twoDecimalPlaces(n) { | ||
return Math.round(n * 100) / 100 | ||
} | ||
|
||
// or | ||
|
||
function twoDecimalPlaces(n) { | ||
return parseFloat(n.toFixed(2)); | ||
} | ||
|
||
twoDecimalPlaces(4.659725356); //, 4.66 | ||
|
||
twoDecimalPlaces(2.675); //, 2.68 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
String.prototype.digit = function() { | ||
return /^\d$/.test(this); | ||
}; | ||
|
||
// mine is below | ||
|
||
|
||
String.prototype.digit = function() { | ||
if (/[a-z\s]/gi.test(this)) return false; | ||
if (this>9) return false; | ||
return /[0-9]/g.test(this); | ||
}; | ||
|
||
''.digit() // , false); | ||
'7'.digit() // , true); | ||
' '.digit() //, false); | ||
'14'.digit() //, false); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function validateCode(code){ | ||
return /^1|^2|^3/g.test(code); | ||
} | ||
|
||
// or | ||
|
||
function validateCode(code){ | ||
return /^[123]/.test(code); | ||
} | ||
|
||
|
||
validateCode(123); // true | ||
validateCode(321); // true | ||
validateCode(421); // false |