Last active
March 12, 2019 14:12
-
-
Save jamesperi/8e020efe39d5c37c7188482c7b7ce03a to your computer and use it in GitHub Desktop.
Javascript Test #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const data = [ | |
{"id": 1, "name": "John", "Group": {"id": 5, "name": "Admin" } }, | |
{"id": 2, "name": "Steve", "Group": {"id": 1, "name": "Accounting" } }, | |
{"id": 3, "name": "Mary", "Group": {"id": 1, "name": "Accounting" } }, | |
{"id": 4, "name": "Dave", "Group": {"id": 5, "name": "Admin" } }, | |
{"id": 5, "name": "Daphnie", "Group": {"id": 2, "name": "Development" } }, | |
{"id": 6, "name": "Jenny", "Group": {"id": 2, "name": "Development" } }, | |
{"id": 7, "name": "Pat", "Group": {"id": 5, "name": "Admin" } } | |
] | |
const output = { | |
"Admin": [ | |
{ "id": 1, "label": "John" }, | |
{ "id": 4, "label": "Dave" }, | |
{ "id": 7, "label": "Pat" } | |
], | |
"Accounting": [ | |
{"id": 2, "label": "Steve" }, | |
{"id": 3, "label": "Mary" } | |
], | |
"Development": [ | |
{"id": 5, "name": "Daphnie" }, | |
{"id": 6, "name": "Jenny" } | |
] | |
} | |
/* | |
Excercize | |
1) Convert "data" array to to "output" object. Assume you don't know the group name values, new ones could be added and your code should handle them. | |
2) Use spread opperator to deconstruct the "output" object, expose Accounting and log its value to console | |
3) Take data and replace index 3 with { id: 10, name: "Jim', Group: {id: 5, name: "Admin" } }. Do not modify data array. | |
4) Using google (or your search of choice), what parameters are passed to the react-virtualized table -> column components => "cellRenderer" method? | |
5) Is the following code valid? Explain. | |
function runSomething(data) { | |
return data + "!" | |
} | |
function runtest(foo) { | |
switch(foo) { | |
case "WORLD": | |
const output = "HELLO " + foo | |
return runSomething(output) | |
case "HELLO": | |
const output = foo + " WORLD" | |
return runSomething(output) | |
} | |
} | |
console.log(runtest('HELLO')) | |
6) Convert functions to arrow functions. | |
7) Use template literals in place of string concatenation. | |
8) Replace switch with an object literal switch.. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment