Add requirement for add function to return boolean (#13404)
This commit is contained in:
@ -230,7 +230,8 @@
|
|||||||
"<blockquote>var set = new Object();<br>set.foo = true;<br>// See if foo exists in our set:<br>console.log(set.foo) // true</blockquote>",
|
"<blockquote>var set = new Object();<br>set.foo = true;<br>// See if foo exists in our set:<br>console.log(set.foo) // true</blockquote>",
|
||||||
"In the next few exercises, we will build a full featured Set from scratch.",
|
"In the next few exercises, we will build a full featured Set from scratch.",
|
||||||
"For this exercise, create a function that will add a value to our set collection as long as the value does not already exist in the set. For example:",
|
"For this exercise, create a function that will add a value to our set collection as long as the value does not already exist in the set. For example:",
|
||||||
"<blockquote>this.add = function(element) {<br> //some code to add value to the set<br>}</blockquote>"
|
"<blockquote>this.add = function(element) {<br> //some code to add value to the set<br>}</blockquote>",
|
||||||
|
"The function should return <code>true</code> if the value is successfully added and <code>false</code> otherwise."
|
||||||
],
|
],
|
||||||
"challengeSeed": [
|
"challengeSeed": [
|
||||||
"function Set() {",
|
"function Set() {",
|
||||||
@ -250,7 +251,9 @@
|
|||||||
],
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
"assert((function(){var test = new Set(); return (typeof test.add === 'function')}()), 'message: Your <code>Set</code> class should have a <code>add</code> method.');",
|
"assert((function(){var test = new Set(); return (typeof test.add === 'function')}()), 'message: Your <code>Set</code> class should have a <code>add</code> method.');",
|
||||||
"assert((function(){var test = new Set(); test.add('a'); test.add('b'); test.add('a'); var vals = test.values(); console.log(vals); return (vals[0] === 'a' && vals[1] === 'b' && vals.length === 2)}()), 'message: Your <code>Set</code> should not add duplicate values.');"
|
"assert((function(){var test = new Set(); test.add('a'); test.add('b'); test.add('a'); var vals = test.values(); console.log(vals); return (vals[0] === 'a' && vals[1] === 'b' && vals.length === 2)}()), 'message: Your <code>Set</code> should not add duplicate values.');",
|
||||||
|
"assert((function(){var test = new Set(); var result = test.add('a'); return (result != undefined) && (result === true);}()), 'message: Your <code>Set</code> should return <code>true</code> when a value has been successfully added.');",
|
||||||
|
"assert((function(){var test = new Set(); test.add('a'); var result = test.add('a'); return (result != undefined) && (result === false);}()), 'message: Your <code>Set</code> should return <code>false</code> when the user tries to add a duplicate value.');"
|
||||||
],
|
],
|
||||||
"type": "waypoint",
|
"type": "waypoint",
|
||||||
"solutions": [],
|
"solutions": [],
|
||||||
|
Reference in New Issue
Block a user