I have a problem, I am trying to assume how many children under the age (as the key ), But we want to get them to be a group of older children (who are older children in this case 4 and 2) on the basis of children; = 4 I want to get the age group of children who can create big groups.
Question How do I get the age of the newly created group with the age of 4 like the first child? So we get input in What I have tried and has been created so far in psudo so far How can we get that light? In Javascript ps sorry that if that title is not correct, then If there is any suggestion Please comment or edit. It's easy. Just make a loop on the kids, like your pseudo In the code.
max_bigest_kids_in_group = 4 child object = {// era 0 has 7 children '0': 7 // There are 3 children in age 1 ': 3/2 2 have 2 children' 2 ': 2/4 years old have 1' 4 'of children: 1 / / says that 3 or 5, 5 No age and so on.
The biggest big effort ('4' = 1) + ('2' (2 = 2) + ('2' = 2) + ('1') ('1' = 3) (do not oke because 1 + 2 + 3 is 6> 4 =) because after that Exact = 4 array [4 and 2] / expected result {'4', '2'} or ['4', '2'] then if max_bigest_kids_in_group = 6 then this ['4', '2', '1' ]
var Children = {'0': 7, // Age 7 has children '1': 3, // Age 3 has 3 children 2 ': 2, // 2 2 has 2 children '4': 1 // Age 4 has 1 child); Function getAgesOfOldestKids (n) {/ * Receive: {number} How many children do start with some magic to detect maximum age in // // set / code with in-loop for children Max = Math.max.apply (empty, object.keys (children)); Var age = []; // Children's age in outcomes; = Var count = 0; // How many children are in the set (var i = max; i> = 0; i--) if (I have children) {// era level count is present = = children [i]; // Add the number of children if children (in the count & gt; N) // set more age than the permission to return; // loop and break the age. Pat (i); // Add this age phase to the result} Return age; // less than requested can be children} & gt; GetAgesOfOldestKids (4) ["4", "2"] // One move to get the number of children in the result: & gt; Var age = [4, 2]; & Gt; Looping children directly to children, other possible and very few solutions, due to age (function (n, age) {return n + child [age]}, 0) 3
< P> Keys:
function getAgesOfOldestKids (n) {/ * Get: {number} How many children * / // era, inferior age group = object. Key (children) .sort (function (a, b) {return ba;}); Var calculation = 0; // How many children are in the set (var i = 0; i & lt; age length -1 & amp; calculation & lt; = n; i ++) calculation + children = [age] ; // Add the aging number of children. 0 (0, i-1); }
Comments
Post a Comment