Skip to content

Commit 47dbb03

Browse files
author
Rafa Paradela
committed
Merge pull request scala-exercises#47 from hasumedic/named-and-default-args
Tiny typo in 'namedanddefaultarguments'
2 parents 67bb3fd + f896138 commit 47dbb03

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app/json/namedanddefaultarguments.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"title": "Named and Default Arguments",
33
"modules": [
44
{
5-
"preparagraph": "When calling methods and functions, you can use the name of the variables expliclty in the call, like so:\n\n```\ndef printName(first:String, last:String) = {\n println(first + \" \" + last)\n}\n\nprintName(\"John\",\"Smith\") // Prints \"John Smith\"\nprintName(first = \"John\",last = \"Smith\") // Prints \"John Smith\"\nprintName(last = \"Smith\",first = \"John\") // Prints \"John Smith\"\n```\n\nNote that once you are using parameter names in your calls, the order doesn’t matter, so long as all parameters are named. This feature works well with default parameter values:\n\n```\ndef printName(first:String = \"John\", last:String = \"Smith\") = {\n println(first + \" \" + last)\n}\nprintName(last = \"Jones\") // Prints \"John Jones\"\n```\n\nGiven classes below:\n\n```\nclass WithoutClassParameters() {\n def addColors(red: Int, green: Int, blue: Int) = {\n (red, green, blue)\n }\n\n def addColorsWithDefaults(red: Int = 0, green: Int = 0, blue: Int = 0) = {\n (red, green, blue)\n }\n}\n\nclass WithClassParameters(val defaultRed: Int, val defaultGreen: Int, val defaultBlue: Int) {\n def addColors(red: Int, green: Int, blue: Int) = {\n (red + defaultRed, green + defaultGreen, blue + defaultBlue)\n }\n\n def addColorsWithDefaults(red: Int = 0, green: Int = 0, blue: Int = 0) = {\n (red + defaultRed, green + defaultGreen, blue + defaultBlue)\n }\n}\n\nclass WithClassParametersInClassDefinition(val defaultRed: Int = 0, val defaultGreen: Int = 255, val defaultBlue: Int = 100) {\n def addColors(red: Int, green: Int, blue: Int) = {\n (red + defaultRed, green + defaultGreen, blue + defaultBlue)\n }\n\n def addColorsWithDefaults(red: Int = 0, green: Int = 0, blue: Int = 0) = {\n (red + defaultRed, green + defaultGreen, blue + defaultBlue)\n }\n}\n\n```\n\nCan specify arguments in any order if you use their names:",
5+
"preparagraph": "When calling methods and functions, you can use the name of the variables explicitly in the call, like so:\n\n```\ndef printName(first:String, last:String) = {\n println(first + \" \" + last)\n}\n\nprintName(\"John\",\"Smith\") // Prints \"John Smith\"\nprintName(first = \"John\",last = \"Smith\") // Prints \"John Smith\"\nprintName(last = \"Smith\",first = \"John\") // Prints \"John Smith\"\n```\n\nNote that once you are using parameter names in your calls, the order doesn’t matter, so long as all parameters are named. This feature works well with default parameter values:\n\n```\ndef printName(first:String = \"John\", last:String = \"Smith\") = {\n println(first + \" \" + last)\n}\nprintName(last = \"Jones\") // Prints \"John Jones\"\n```\n\nGiven classes below:\n\n```\nclass WithoutClassParameters() {\n def addColors(red: Int, green: Int, blue: Int) = {\n (red, green, blue)\n }\n\n def addColorsWithDefaults(red: Int = 0, green: Int = 0, blue: Int = 0) = {\n (red, green, blue)\n }\n}\n\nclass WithClassParameters(val defaultRed: Int, val defaultGreen: Int, val defaultBlue: Int) {\n def addColors(red: Int, green: Int, blue: Int) = {\n (red + defaultRed, green + defaultGreen, blue + defaultBlue)\n }\n\n def addColorsWithDefaults(red: Int = 0, green: Int = 0, blue: Int = 0) = {\n (red + defaultRed, green + defaultGreen, blue + defaultBlue)\n }\n}\n\nclass WithClassParametersInClassDefinition(val defaultRed: Int = 0, val defaultGreen: Int = 255, val defaultBlue: Int = 100) {\n def addColors(red: Int, green: Int, blue: Int) = {\n (red + defaultRed, green + defaultGreen, blue + defaultBlue)\n }\n\n def addColorsWithDefaults(red: Int = 0, green: Int = 0, blue: Int = 0) = {\n (red + defaultRed, green + defaultGreen, blue + defaultBlue)\n }\n}\n\n```\n\nCan specify arguments in any order if you use their names:",
66
"code": "val me = new WithoutClassParameters()\n\n// what happens if you change the order of these parameters (nothing)\nval myColor = me.addColors(green = 0, red = 255, blue = 0)\n\n// for koan, remove the values in the should equal\nmyColor should equal(__, __, __)",
77
"solutions": [
88
"255",
@@ -61,4 +61,4 @@
6161
"postparagraph": ""
6262
}
6363
]
64-
}
64+
}

0 commit comments

Comments
 (0)