Skip to content

Instantly share code, notes, and snippets.

@mgng
Last active December 23, 2015 00:09
Show Gist options
  • Save mgng/6551900 to your computer and use it in GitHub Desktop.
Save mgng/6551900 to your computer and use it in GitHub Desktop.
期間がかぶってたらエラーにする
function isDuplicate( list ) {
var _list = list.concat();
while( _list.length ) {
var cur = _list.pop();
for( var i=0,l=_list.length; i<l; i++ ) {
if (
( _list[i][0] <= cur[0] && cur[0] <= _list[i][1] )
||
( _list[i][0] <= cur[1] && cur[1] <= _list[i][1] )
) {
return true;
}
}
}
return false;
}
var list = [
[ 20130910, 20130915 ],
[ 20130916, 20130920 ],
[ 20130918, 20130923 ]
];
if ( isDupulicate( list ) ) {
alert( 'かぶってます!' )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment