Kevin.Pheasey
BAN USER- 0of 0 votes
AnswersCreate a basic implementation of Deferred.
- Kevin.Pheasey in United States for AWS
Deferred#resolve => Marks the deferred / promise as completed successfully and calls success callbacks
Deferred#reject => Marks the deferred / promise as failed and calls failed callbacks
Deferred#promise => Returns promise object for watching completion
#addCallback => Adds a callback function to be called if the activity is successful
#addFailCallback => Adds a callback function to be called if the activity fails
var promise = myAsyncThingy(); // Call the API that starts some async work and returns a promise
promise.addCallback(function () { console.log("We did it"); }); // Register a success callback
promise.addFailCallback(function () { console.error("We failed"); }); // Register a failure callback
function myAsyncThingy() {
var def = new Deferred(); // Create a deferred to use for managing our async behavior
setTimeout(function () { def.resolve() }, 1000); // In one second call the resolve function to mark it as success
return def.promise(); // return the promise for our deferred to the client
}| Report Duplicate | Flag | PURGE
Amazon Web Developer - 3of 3 votes
AnswersUsing the mythical Hydra as an example, create a button that is destroyed by clicking it, but two new buttons are created in it's place.
- Kevin.Pheasey in United States for AWS| Report Duplicate | Flag | PURGE
Amazon Web Developer JavaScript - 2of 2 votes
AnswersCreate a function that will reverse the words in a sentence.
- Kevin.Pheasey in United States for AWS| Report Duplicate | Flag | PURGE
Amazon Web Developer JavaScript
I bombed this because I was unsure of the syntax for creating objects with JavaScript. But here's what I ended up with.
function Deferred(){
var callbackSuccess = [];
var callbackFail = [];
this.resolve = function(){
for(var i = 0; i < callbackSuccess.length; i++){
callbackSuccess[i]();
}
};
this.reject = function(){
for(var i = 0; i < callbackFail.length; i++){
callbackFail[i]();
}
};
this.promise = function(){
function Promise(){
// This is where I was lost on syntax and we just talked
// about how it would work instead.
}
return new Promise();
}
}
The question is tagged as JavaScript and as Web Developer.
- Kevin.Pheasey April 10, 2013This is the answer I gave:
<div id="hydra">
<button onclick="strikeDown(this);">Head</button>
</div>
<script>
function strikeDown(button){
$(this).remove();
$('#hydra').append('<button onclick="strikeDown(this);">Head</button>');
$('#hydra').append('<button onclick="strikeDown(this);">Head</button>');
}
</script>
The interviewer didn't comment on whether or not this was the best answer, he only mentioned it was correct.
- Kevin.Pheasey April 10, 2013The interviewer said it was exactly what they were looking for.
function reverse(sentence){
return sentence.split(" ").reverse().join(" ");
}
Remember this is JavaScript, not Java.
- Kevin.Pheasey April 10, 2013
Repdeloresrdaniels, Cloud Support Associate at JDA
Crossed the country marketing wool in Nigeria. Was quite successful How to Get Girlfriend Back By Vashikaran Mantra . Spent a ...
Repmendezleah216, Analyst at Bosch
Hello,everybody,I'm Leah Mendez.I want to make some friends here.I’m a woman with ambition and ...
Repmakaylamelua, Blockchain Developer at AMD
I am a sound editing and music composer with experience of handling a wide variety of programs.During my free ...
RepShastri Ji is well known hindi and tamil vashikaran specialist. He will give you effective and simple totke to control ...
Repclarasbarr, Korean Air Change Flight at Adap.tv
I am ClaraBarr from California USA. Writes and records various different genres for television, film and other artists.Wrote several ...
Repannasteven1246, Analyst at Accenture
Creative, highly visual fashion professional who can brilliantly mix and match the technical expertise and intuition like fabric and color ...
Repwilliamchansen95, Computer Scientist at 247quickbookshelp
I am working as a manager in Lionel Kiddie City company. I really enjoy my job. I like to play ...
Repmerrittmonique9, Android Engineer at AMD
I am Monique and working in high court from last 20 years.Handel many cases in my career.Build and ...
RepI am Susan From Wasilla USA. and my strong interest in yoga and reading historical books. I have a large ...
RepHuge collection of cheap ammo for Rifle, Handgun, Shotgun & Rimfire from top brands you are looking for.
RepGinaSanchez, Computer Scientist at Autoportal.com
Ginna from New York.Successfully managing a high volume of work assignments without compromising quality to exceed client expectations.Apart ...
Repnicolealove786, Apple Phone Number available 24/7 for our Customers at Argus
I am Nicole from Beverly Hills, CA. I am working as a manager in Liberty Wealth Planner company. I also ...
There are a couple pitfalls such as apply a click listener to buttons.... The following would apply multiple listeners to buttons and may cause multiple heads to appear. Additionally, it does not create new buttons, just copies of the one being destroyed.
- Kevin.Pheasey April 11, 2013