5 kyu
Randomize Objects
320 of 322surtich
Description:
Implement the following methods:
Object.prototype.random()
: returns randomly one of the values of the object.
For example:
var obj = {
a: 1,
b: {
x: 2,
y: 3
},
c: {
z: {
q: 4
}
}
};
obj.random(); //returns 1 or 2 or 3 or 4. All values have the same probability to be returned
obj = {};
obj.random(); //returns undefined
Object.prototype.toRandomArray()
: returns an array of the random values.
For example,
var obj = {
a: 1,
b: {
x: 2,
y: 3
},
c: {
z: {
q: 4
}
}
};
obj.toRandomArray(); //returns a random permutation of [1, 2, 3, 4]
obj = {};
obj.toRandomArray(); //returns []
Algorithms
Fundamentals
Arrays
Similar Kata:
Stats:
Created | Feb 18, 2014 |
Published | Feb 18, 2014 |
Warriors Trained | 872 |
Total Skips | 133 |
Total Code Submissions | 4915 |
Total Times Completed | 322 |
JavaScript Completions | 320 |
Total Stars | 33 |
% of votes with a positive feedback rating | 90% of 62 |
Total "Very Satisfied" Votes | 52 |
Total "Somewhat Satisfied" Votes | 7 |
Total "Not Satisfied" Votes | 3 |