Programming › Brain Teaser: Recursive Anonymous Function Expression Analysis by romme2u(op): 1:51am On Oct 20, 2018*. Modified: 12:53am On Oct 31, 2018 |
I have over-studied in recent weeks as I’ve read more than I write (code)  There is a technique that has been flying over my head for over a year (probably because I didn’t take it serious at first). I came across it in Douglas Crockford’s “JavaScript the Good Parts” while studying advanced function techniques late last year. Here is a sample: //JS Memoization //memo is a one dimensional array for storing pre-defined numbers....... //the function returns a value if it already exists in the array....... //.......else generate and store a value for future use, then return the generated value var memoizer = function (memo, fundamental) { var shell = function (n) { var result = memo[n]; if (typeof result !== 'number') { result = fundamental(shell, n); memo[n] = result; } return result; }; return shell; }; //fundamental function can be a Factorial, Fibonacci series generator, fetching data over a network or any processor intensive task
Here is it counterpart in PHP (Source – User Comment on PHP online manual): //PHP Multi-Dimension Array Restructuring --- handles 2D to nD arrays as memory permits //Designed to rearrange $_FILES superglobal from associative to numeric array when multiple files are uploaded at once function get_fixed_files() { $function = function($files, $fixed_files = [], $path = []) use (&$function) { foreach ($files as $key => $value) { $temp = $path; $temp[] = $key; if (is_array($value)) { $fixed_files = $function($value, $fixed_files, $temp); } else { $next = array_splice($temp, 1, 1); $temp = array_merge($temp, $next); $new = &$fixed_files; foreach ($temp as $key) { $new = &$new[$key]; } $new = $value; } } return $fixed_files; }; return $function($_FILES); }
Both piece of code uses same technique (Recursive Anonymous Function Expression) to solve two different problems. My issue is not recursive functions as I understand the concept. But since recursive function usually suffers from memory constraint and can most time be rewritten as iterative, I have never used it as iteration presents a more readable code to me. It seems the PHP code uses the Tower of Hanoi concept to rearrange the data structure. It is just a guess, I’m not really sure. ModifiedThanks Nmeri17, the question didn't fit the Q&A format required by stack overflow.........I just needed to reword the question, sorry for the oversight. I have also provided context and expected data structure The correct question should be Convert these Recursive functions to Iterative functions (rewrite as)I understand that some problems suit recursive technique more than iterative but i just need an insight |
Politics › Re: Atiku Speaks On Meeting Obasanjo, Oyedepo, Kukah, Sheik Gumi by romme2u: 10:24am On Oct 12, 2018 |
ekestic1976: Are you unemployed?  na now u know say majority of our yoot are unemployed |
Politics › Re: Is This How Atiku Wants To Run The Economy? by romme2u: 12:38pm On Oct 11, 2018 |
onatisi: God bless you . In fact they and those who employed them should be sacked . They keep trying to attack atiku personality and the more they do so,they are making ppl see the huge potentials in atiku  interesting times ahead |
Politics › Re: Ibe Kachikwu Lied About Graduating With First Class From UNN - Premium Times by romme2u: 12:30pm On Oct 11, 2018 |
|
Programming › Re: Looking For Php Freelancers To Work On A Big Project With Me by romme2u: 12:13pm On Oct 11, 2018 |
talk2hb1: Him no want us, maybe op fit host me for him house while working on his project Baba, na idea be this ooohhh OP i go follow for this one |
Romance › Re: Wife Caught Having Sex With The Gateman. Advice Needed! by romme2u: 12:10pm On Oct 11, 2018 |
 why follow only f |
Romance › Re: A Senior Female Colleague Wants Me To Marry Her by romme2u: 11:56am On Oct 11, 2018 |
pansophist: Boss13, You just photocopy my mind with your comments on this thread. You be winch ni? 
@Op, if having kids is really important for you, then consider the fact that women fertility peaks at age 24. Marrying an older woman is a disservice to your offspring as it posses a risk of not been healthy, with lots of birth complications.
In Russia, there is a saying that career women are barren women. Her desperation to get married is just a natural circle in a woman's life where even in the midst of wealth and a high social status, fulfilling her biological task of motherhood triumphs. Feminist lied to women in this area and sadly, most bought into it.
As someone that works with women, and a due observer of their conversations, your respect as a man is gone if you marry a woman of higher social and financial status. It's in contrary to her hypergamous nature especially during pregnancy when she will need the full time protection and resources of a stronger man. Its only a matter of time. And even if she is a unicorn, her family and friends will see you as the worse of men.
A woman that marries a king is automatically a queen. A man that marries a queen is not automatically the king. Goodluck Respect is earned not given.................you seriously need to up your game. Be the A |
Romance › Re: A Senior Female Colleague Wants Me To Marry Her by romme2u: 11:43am On Oct 11, 2018 |
Boss13: I’m sorry about your plight. I don’t know if you are newly married. That’s women for you. Ignore her during issues but ensure that your power and influence do not reduce in the family. It’s good you have increased your earning capacity- regardless of what you think she would be concerned. Most men do not understand that women have this innate insecurity or fear and sometimes such fears drive them to do inexplicable things.
Your wife would come around especially when she begins to see that you are truly committed in the marriage and when old age begin to settle in (laughs)- they all do.
Men know this - your wife or girlfriend is always thinking if this marriage/relationship breaks what is their backup plan. They will never own up, but they all do As much as i respect your views on this issue but i don't think marriage (and relationship in general) should be a battle ground or a war-zone..... They are times a man has to yield to a woman yearnings to placate and balance the tilt of power in the family (especially when it comes to areas she is competent or well-versed). In contemporary times marriage should be like partnership where partners consults each other on issues that will affect the partnership irrespective of the fact that a man has the veto power to override things as the case may be.............communication is the soul of everything as we disagree to agree.. When a relationship degrades to supremacy fight then such a toxic relationship is nearing its end of life..............as pettiness should not rear its ugly head in relationships especially marriage |
Romance › Re: A Senior Female Colleague Wants Me To Marry Her by romme2u: 11:26am On Oct 11, 2018 |
1StopRudeness: There are so many angles to look at this but the angle u are looking from is not even important...how does her miney and position in the office affect hiw u feel for each orher. My own is..if the sex is not great...as in, u know u are not really giving her earth chattering orgasm. And shes just managing it.....ladies know how to manage, especially when all they want is the marriage title and speerm to give them them one or two kids......u go still hear am later ooo
U cannot be enjoying a ladies money and still not be able to fvck her proper....which kind nonsense be that  ma brother na sense go finally kee you nice feast for poco, amberon n co...............surprised i no see amazontopaz n saff |
Programming › Re: Looking For Php Freelancers To Work On A Big Project With Me by romme2u: 8:00pm On Oct 10, 2018 |
talk2hb1: So Developers scarce for Abuja, naso Lagos Developers too dey pop face.  what of us wey no dey Abuja n Lagos |
Jobs/Vacancies › Re: Will I Ever Get A Good Job In Nigeria In This Condition? by romme2u: 7:58pm On Oct 10, 2018 |
 To those who always say school is not important....... It is always the foundation and can serve as a back-up when all else come crashing down |
Politics › Re: Why Nigeria Is Being Encircled By Military Bases. by romme2u: 7:49pm On Oct 10, 2018 |
kunleweb: You made my day with the mastery of intellects that so easily flowed through every line.
I like this part :
Imagine you allowing a certificateless individual to head your organization over you then imagine the same person to be the governor of CBN. A man who is not even worthy to be a village headmaster. Will you even send your child to primary school with a certificateless headmaster? Yet this is whom the convoluted brain cells Nigerians ( highly schooled so called educated people) carry supported.
See why i told you it's hi time, we of same ideologies begin to cluster.
Can't wait for the referendum to come brilliant Nigeria is filled with obtuse set of people............i painfully discovered that in 2015 |
Jobs/Vacancies › Re: The Truths Don Dy Come Out........ by romme2u: 7:45pm On Oct 10, 2018 |
 nwaAmikpe firefire oooooooohhhhhhhhhhhhhhhhhhhhh |
Politics › Re: Nigeria Youths Cheering Over Atiku’s Victory A SHAME – Charly Boy by romme2u: 7:39pm On Oct 10, 2018 |
hungryboy: To unseat Buhari isn't a game for political novices like Sowore, Moghalu, Durotoye et al
Buhari is no Jonathan that will easily leave power To show you how much he likes power, he contested for four consecutive times.
To unseat Buhari will be a war, money for money, rigging for rigging , bribing for bribing, if anybody stands a chance against the Dullard in Chief, it's the experienced Atiku.
But am no supporter of either of 'em though, my only wahala now na to find one old oyinbo woman for facebook marry, use am get Visa, run leave this Country  my brother the spirit is ministering to you |
Foreign Affairs › Re: Russia To Supply Syria With S-300 Anti-missile System by romme2u: 1:54am On Sep 29, 2018 |
 ghen ghen |
Romance › Re: Man Carries His Fiancee On His Shoulder Inside Swimming Pool In Pre-wedding Pics by romme2u: 1:32am On Sep 29, 2018 |
OboOlora: Baba u funny die! Try change ur username to haloperidol sha, u need am pass lexotan  abeg wetin e mean |
Romance › Re: Why Am I Attracted To Teenage Girls? by romme2u: 1:18am On Sep 24, 2018 |
 probably in your early or mid-twenties it is normal either you are more comfortable in their presence or they excite you sexually |
Romance › Re: Will Cristiano Ronaldo And I Make A Good Couple? by romme2u: 1:15am On Sep 24, 2018 |
 centuarXXXV we're going international |
Politics › Re: Breaking News: FG Suspends National Carrier, Nigeria Air Indefinitely by romme2u: 1:14am On Sep 20, 2018 |
|
Romance › Re: No Guy Can Actually F*ck A Girl Till Her Leg Shake, We Fake It’– Lady Says: by romme2u: 12:22pm On Aug 15, 2018 |
Babyforever: Keep pounding  can't you give person hope haba |
Politics › Re: Breaking News:Buhari Extended His Leave Notified National Assembly by romme2u: 12:16pm On Aug 15, 2018 |
HoluwarTohbar: Lamentations of brother Jero.. Why not offer yourself, are you not qualified?
Buhari has refused to disclose the source of his ailment but has continued to spend our Commonwealth for his medical bills. So much for the much touted integrity.  haaaaaaaaaaaa..........easy on that closet zoneB |
Romance › Re: Photos Of A Couple Having Sex On A Hotel Balcony, Passerbye Reacts by romme2u: 12:13pm On Aug 15, 2018 |
megareal: Konji na bastard. It can reset even the hardest brains.   xcept mine |
Politics › Re: SERAP Sues NYSC Over Failure To Publish Kemi Adeosun’s ‘exemption Certificate’ by romme2u: 11:32am On Aug 15, 2018 |
LadyExcellency: Reading opinions on Nairaland is like researching the level of uncivilization and backwardness of African Youths, a case study of Nigerian youths opinions on social media.  most do it purposely for attention seeking...............like the one above you mimicking that bbq guy |
Romance › Re: Where Do Girls Meet And Marry Guys Living In The US ? by romme2u: 11:00am On Aug 15, 2018 |
Saff: What are the chances of every Nigerian wishing to locate to get to the USA or Canada? I don’t really know the struggle as I was born and raised in the U.K. Just from looking at family members and seeing other people locating to places around the world, it’s not as rosy as it may seem. It’s hard everywhere and if you can build yourself in Nigeria then do it. 
|
Romance › Re: Where Do Girls Meet And Marry Guys Living In The US ? by romme2u: 10:57am On Aug 15, 2018 |
|
Business › Re: Report: Banking Access Lowest In Northeast, Southeast by romme2u: 10:34am On Aug 15, 2018 |
hisgrace090: Nigerian banks are opportunist.
Only their interest count.  Majority of people in Nigeria are same |
Education › Re: So What's Next For You After Graduation? by romme2u: 10:29am On Aug 15, 2018 |
deepwater: N Y S C
Now Your Suffering Continuous  |
Politics › Re: Akpabio Walking Against The Tide And The Will Of His People-secondus by romme2u: 1:51pm On Aug 13, 2018 |
DDeliverer: Haha..I dey Boss. I just dey observe from one side..  na so........nothing do you |
Politics › Re: 17 Signs Of Highly Intelligent People by romme2u: 2:16am On Aug 11, 2018 |
 ......and I Daniel understood by books |
Politics › Re: 17 Signs Of Highly Intelligent People by romme2u: 2:15am On Aug 11, 2018 |
 ......and I Daniel learnt by books |
Family › Re: A Thread For Shy People by romme2u: 3:43am On Aug 09, 2018 |
AmoryBlacq: Only me shy, introverted, broke, fugly, girlfriendless!
I just tire!  Timid nko |
Politics › Re: See Saraki's Reaction When He Was Told Of Akpabio's Defection To APC(photo) by romme2u: 3:28am On Aug 09, 2018 |
|