-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuckduckgoose.js
More file actions
23 lines (18 loc) · 796 Bytes
/
Duckduckgoose.js
File metadata and controls
23 lines (18 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
Instructions:
DESCRIPTION:
The objective of Duck, duck, goose is to walk in a circle, tapping on each player's head until one is chosen.
Task: Given an array of Player objects (an array of associative arrays in PHP) and an index (1-based), return the name of the chosen Player(name is a property of Player objects, e.g Player.name)
Example:
duck_duck_goose([a, b, c, d], 1) should return a.name
duck_duck_goose([a, b, c, d], 5) should return a.name
duck_duck_goose([a, b, c, d], 4) should return d.name
// PHP only
duck_duck_goose([$a, $b, $c, $d], 1); // => $a["name"]
duck_duck_goose([$a, $b, $c, $d], 5); // => $a["name"]
duck_duck_goose([$a, $b, $c, $d], 4); // => $d["name"]
*/
//Answer
function duckDuckGoose(players, goose) {
return players[(goose - 1) % players.length].name;
}