6 kyu

I Promise Not To Optimize

1,721dcsmith

Description:

This kata is inspired by @Voile's anti-optimizer kata, so you might want to do that one first. In that kata, you task yourself to be as inefficient as possible, and delay returning the result of a function for at least 11 seconds (to fit into Codewars' 12-second timeout limit).

After you successfully implement your antiOptimize function, the second phase of your evil plot kicks into gear, and you deploy anti-optimized code everywhere in your production server. But the higher-ups are catching on! -- they demand that functions return their result as quickly as possible, or else you risk being fired.

You wallow in despair, unable to bring your dream of inefficiency to reality, but finally realize there's a way you can keep everything woefully inneficient, while still immediately returning values from functions -- Promises!

So now your task is to write the function antiOptimizeAsync, which takes a single parameter task (a function), and immediately returns a Promise that only resolves to the return value of task() at least 11 seconds (and at most 12 seconds) after antiOptimizeAsync is called.

As with Voile's kata, task will always be an arbitrary function that might run for any duration between 0 to 10 seconds.

Promises
Asynchronous
Fundamentals

Similar Kata:

More By Author:

Check out these other kata created by dcsmith

Stats:

CreatedMar 20, 2017
PublishedMar 21, 2017
Warriors Trained3380
Total Skips41
Total Code Submissions22421
Total Times Completed1721
JavaScript Completions1721
Total Stars48
% of votes with a positive feedback rating80% of 125
Total "Very Satisfied" Votes92
Total "Somewhat Satisfied" Votes16
Total "Not Satisfied" Votes17
Total Rank Assessments9
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • dcsmith Avatar
  • Voile Avatar
Ad