Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question 1:
- var each = function(collection, callback) {
- if (Array.isArray(collection)){
- for (var i = 0; i < collection.length; i++) {
- callback(collection[i], i, collection);
- }
- } else if (typeof collection === 'object'){
- for (var key in collection) {
- callback(collection[key], key, collection);
- }
- }else{
- return 'not an array or object';
- }
- };
- Type of is incorrect should be array.isarray.
- Problems with iteartor function does not pass
- Needs to have a call back function
- Question 2
- var addRandomAgeInclusive = function(string, a, b) {
- if(a > b) {
- return string;
- }
- else if (typeof string === "string") {
- var name_object = {};
- name_object['name'] = string;
- name_object['age'] = Math.round(Math.random()*(b-a)+a);
- return name_object
- }
- else if (typeof string === "object") {
- for (var key in string) {
- if (key === "name") {
- string['age'] = Math.round(Math.random()*(b-a)+a);
- }
- else {
- return string;
- }
- }
- }
- return string;
- }
- addRandomAgeInclusive({ name: 'Sean', id: 10330293 }, 30, 40)
Add Comment
Please, Sign In to add comment