Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add friday13th method #720

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ is(13).thirteen(); // true
is(12.8).roughly.thirteen(); // true
is(6).within(10).of.thirteen(); // true
is(2008).yearOfBirth(); // true
is(new Date("2020-03-13")).friday13th(); // true

// check your math skillz
is(4).plus(5).thirteen(); // false
Expand Down
2 changes: 2 additions & 0 deletions consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const THIRTEEN = 13;
const THIRTEEN_FUZZ = 0.5;
const FRIDAY = 5;

var thirteenStrings = [
"xiii", // Roman numeral 13
Expand Down Expand Up @@ -354,5 +355,6 @@ var thirteenStrings = [
module.exports = {
THIRTEEN: THIRTEEN,
THIRTEEN_FUZZ: THIRTEEN_FUZZ,
FRIDAY: FRIDAY,
thirteenStrings: thirteenStrings
};
7 changes: 7 additions & 0 deletions is.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var consts = require('./consts');

const THIRTEEN = consts.THIRTEEN;
const THIRTEEN_FUZZ = consts.THIRTEEN_FUZZ;
const FRIDAY = consts.FRIDAY;
const thirteenStrings = consts.thirteenStrings;

'use strict';
Expand Down Expand Up @@ -107,6 +108,12 @@ var is = function is(x) {
}
return currYear - parseInt(x) == THIRTEEN
},
friday13th: function() {
if (Object.prototype.toString.call(x) !== '[object Date]') {
return false;
}
return x.getDay() === FRIDAY && x.getDate() === THIRTEEN;
},
plus: function(y) {
return is(x + y);
},
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ tap.equal(is("https://www.imdb.com/title/tt2991516/").thirteen(), true);
//year of birth test
tap.equal(is("2003").yearOfBirth(), false);

// Friday 13th test
tap.equal(is("not a date").friday13th(), false);
tap.equal(is(new Date("2020-06-13")).friday13th(), false);
tap.equal(is(new Date("2018-07-13")).friday13th(), true);

// Imaginary 13's tests
tap.equal(is("13+0i").thirteen(), true);
tap.equal(is("13i").thirteen(), true);
Expand Down