Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李楚霏
/
refactorTest
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e3923306
authored
May 24, 2020
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
task-8-if-conditions -- refactor updateQuality
function And refactor updateQualityAfterExpired Fun simply
parent
13c57e5a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
83 deletions
+86
-83
gildedRose/src/AgedBrie.js
+14
-9
gildedRose/src/BackstagePass.js
+31
-10
gildedRose/src/Sulfuras.js
+10
-11
gildedRose/src/item.js
+31
-53
No files found.
gildedRose/src/AgedBrie.js
View file @
e3923306
import
{
Item
}
from
"./item"
;
import
{
Item
}
from
'./item'
export
class
AgedBrie
extends
Item
{
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
);
this
.
name
=
'Aged Brie'
;
};
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
)
this
.
name
=
'Aged Brie'
}
isAgedBrie
()
{
return
'Aged Brie'
;
isAgedBrie
()
{
return
'Aged Brie'
}
updateQuality
(
item
)
{
if
(
item
.
quality
<
50
)
{
item
.
quality
=
item
.
quality
+
1
}
}
\ No newline at end of file
}
}
gildedRose/src/BackstagePass.js
View file @
e3923306
import
{
Item
}
from
"./item"
;
import
{
Item
}
from
'./item'
export
class
BackstagePass
extends
Item
{
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
);
this
.
name
=
'Backstage passes to a TAFKAL80ETC concert'
;
}
isBackStage
()
{
return
'Backstage passes to a TAFKAL80ETC concert'
;
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
)
this
.
name
=
'Backstage passes to a TAFKAL80ETC concert'
}
isBackStage
()
{
return
'Backstage passes to a TAFKAL80ETC concert'
}
updateQuality
(
item
)
{
if
(
item
.
name
===
this
.
isBackStagePass
())
{
if
(
item
.
quality
<
50
)
{
if
(
item
.
sell_in
<
11
)
{
if
(
item
.
quality
<
50
)
{
item
.
quality
=
item
.
quality
+
1
}
}
if
(
item
.
sell_in
<
6
)
{
if
(
item
.
quality
<
50
)
{
item
.
quality
=
item
.
quality
+
1
;
}
}
}
return
;
}
}
updateQualityAfterExpired
(
item
)
{
if
(
item
.
quality
<
50
)
{
item
.
quality
=
item
.
quality
+
1
}
}
\ No newline at end of file
}
}
gildedRose/src/Sulfuras.js
View file @
e3923306
import
{
Item
}
from
"./item"
;
import
{
Item
}
from
'./item'
export
class
Sulfuras
extends
Item
{
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
);
this
.
name
=
'Sulfuras, Hand of Ragnaros'
;
}
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
)
this
.
name
=
'Sulfuras, Hand of Ragnaros'
}
isSulfuras
()
{
return
'Sulfuras, Hand of Ragnaros'
;
}
}
\ No newline at end of file
isSulfuras
()
{
return
'Sulfuras, Hand of Ragnaros'
}
updateQuality
(
item
)
{}
}
gildedRose/src/item.js
View file @
e3923306
...
...
@@ -10,15 +10,15 @@ export class Item {
}
isAgedBrie
()
{
return
'Aged Brie'
;
return
'Aged Brie'
}
isSulfuras
()
{
return
'Sulfuras, Hand of Ragnaros'
;
return
'Sulfuras, Hand of Ragnaros'
}
isBackStagePass
()
{
return
'Backstage passes to a TAFKAL80ETC concert'
;
return
'Backstage passes to a TAFKAL80ETC concert'
}
toString
()
{
...
...
@@ -26,84 +26,62 @@ export class Item {
}
createBackStagePass
(
sell_in
,
quality
)
{
new
BackStagePass
(
'Backstage passes to a TAFKAL80ETC concert'
,
sell_in
,
quality
);
new
BackStagePass
(
'Backstage passes to a TAFKAL80ETC concert'
,
sell_in
,
quality
)
}
createSulfuras
(
sell_in
,
quality
)
{
new
Sulfuras
(
sell_in
,
quality
)
;
new
Sulfuras
(
sell_in
,
quality
)
}
createNormalItem
(
name
,
sell_in
,
quality
)
{
new
Item
(
name
,
sell_in
,
quality
)
;
new
Item
(
name
,
sell_in
,
quality
)
}
createAgedBrie
(
sell_in
,
quality
)
{
new
AgedBrie
(
sell_in
,
quality
)
;
new
AgedBrie
(
sell_in
,
quality
)
}
_updateItem
(
item
)
{
this
.
updateQuality
InOneDay
(
item
);
this
.
updateSellIn
InOneDay
(
item
);
this
.
updateQualityAfter
Devaluation
(
item
);
this
.
updateQuality
(
item
)
this
.
updateSellIn
(
item
)
this
.
updateQualityAfter
Expired
(
item
)
}
updateQualityInOneDay
(
item
)
{
if
(
item
.
name
!=
this
.
isAgedBrie
()
&&
item
.
name
!=
this
.
isBackStagePass
())
{
if
(
item
.
quality
>
0
)
{
if
(
item
.
name
!=
this
.
isSulfuras
())
{
item
.
quality
=
item
.
quality
-
1
}
}
}
else
{
if
(
item
.
quality
<
50
)
{
this
.
updateQualityAfterExpired
(
item
)
if
(
item
.
name
==
this
.
isBackStagePass
())
{
if
(
item
.
sell_in
<
11
)
{
if
(
item
.
quality
<
50
)
{
this
.
updateQualityAfterExpired
(
item
);
}
}
if
(
item
.
sell_in
<
6
)
{
if
(
item
.
quality
<
50
)
{
this
.
updateQualityAfterExpired
(
item
);
}
}
}
}
updateQuality
(
item
)
{
if
(
item
.
quality
>
0
)
{
item
.
quality
=
item
.
quality
-
1
}
}
updateSellIn
InOneDay
(
item
)
{
if
(
item
.
name
!
=
this
.
isSulfuras
())
{
this
.
decreaseSellIn
(
item
)
updateSellIn
(
item
)
{
if
(
item
.
name
==
=
this
.
isSulfuras
())
{
return
}
this
.
decreaseSellInOneDay
(
item
)
}
updateQualityAfterDevaluation
(
item
)
{
updateQualityAfterExpired
(
item
)
{
if
(
item
.
sell_in
>=
0
)
{
return
}
if
(
item
.
sell_in
<
0
)
{
if
(
item
.
name
!=
this
.
isAgedBrie
())
{
if
(
item
.
name
!=
this
.
isBackStagePass
())
{
if
(
item
.
quality
>
0
)
{
if
(
item
.
name
!=
this
.
isSulfuras
())
{
item
.
quality
=
item
.
quality
-
1
}
}
else
{
item
.
quality
=
item
.
quality
-
item
.
quality
if
(
item
.
name
!==
this
.
isAgedBrie
())
{
if
(
item
.
quality
>
0
)
{
if
(
item
.
name
!==
this
.
isSulfuras
())
{
item
.
quality
=
item
.
quality
-
1
}
}
else
{
if
(
item
.
quality
<
50
)
{
this
.
updateQualityAfterExpired
(
item
);
}
item
.
quality
=
item
.
quality
-
item
.
quality
}
}
}
}
decreaseSellIn
(
item
)
{
decreaseSellIn
OneDay
(
item
)
{
item
.
sell_in
=
item
.
sell_in
-
1
}
updateQualityAfterExpired
(
item
)
{
item
.
quality
=
item
.
quality
+
1
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment