Even Rubber Duck knows JS better than you!

Even Rubber Duck knows JS better than you!

A2443b68836f2d166eae52b940e99bf6?s=128

Nikita Galkin

September 08, 2018
Tweet

Transcript

  1. Even Rubber Duck knows JavaScript better than you! by Nikita

    Galkin Sep 8, 2018
  2. Bug on line 7 Quack Quack

  3. Your code is sucks Quack Quack

  4. None
  5. class Employee { constructor(role) { this.role = role; } get

    mainResponsibility() { switch (this.role) { case 'Developer': return 'Write Code'; ...
  6. Turn and Write Code

  7. 7 Hiring process 1. HR-interview 2. CV-screening 3. Technical interview

    4. Interview with the client Dev Team
  8. Upgraded Hiring process 1. HR-interview 2. CV-screening 3. Live coding

    as fail fast check 4. Technical interview 5. Test task as second chance 6. Interview with the client 8
  9. Live coding • 20 minutes only • Remote via skype

    with screen-sharing • Without bla-bla bullshit • 4-6 trivial JS tasks at JSfiddle • Easy to see does the code work or not • Googling or Asking is okey 9
  10. Expectations Reality VS

  11. None
  12. You lost context Quack

  13. const obj = { fullname: 'Yellow Duck', getFullname: function() {

    return this.fullname; } }; const nameGetter = obj.getFullname; // @todo fix this line document.getElementById('name').innerHTML = nameGetter();
  14. const obj = { fullname: 'Yellow Duck', getFullname: function() {

    return this.fullname; } }; const nameGetter = obj.getFullname; // @todo fix this line document.getElementById('name').innerHTML = obj.fullname;
  15. const fullname = 'Yellow Duck'; const obj = { getFullname:

    function() { return fullname; } }; const nameGetter = obj.getFullname; // @todo fix this line document.getElementById('name').innerHTML = nameGetter();
  16. const obj = { fullname: 'Yellow Duck', getFullname: function() {

    return this.fullname; } }; const nameGetter = obj.getFullname.bind(obj); document.getElementById('name').innerHTML = nameGetter();
  17. 17

  18. Just return new promise Quack Quack

  19. function wait(timeout) { // @todo implement } wait(1000) .then(() =>

    { document.getElementById('answer').innerHTML = 'Done!'; });
  20. function wait(timeout) { return { then: function(callback) { callback(); }

    } } wait(1000) .then(() => { document.getElementById('answer').innerHTML = 'Done!'; });
  21. function wait(timeout) { setTimeout(function() {}, timeout); } wait(1000) .then(() =>

    { document.getElementById('answer').innerHTML = 'Done!'; });
  22. function wait(timeout) { setTimeout(function() { return Promise(); }, timeout); }

    wait(1000) .then(() => { document.getElementById('answer').innerHTML = 'Done!'; });
  23. Release the Quacken!

  24. function wait(timeout) { return new Promise(r => setTimeout(r, timeout)); }

    wait(1000) .then(() => { document.getElementById('answer').innerHTML = 'Done!'; });
  25. Use data structure Quack Quack

  26. const unfiltered = [1, 2, 3, 5, 1, 5, 9,

    1, 2, 8]; const filtered = removeDuplicates(unfiltered); // filtered should be equal [1, 2, 3, 5, 9, 8] document.getElementById('answer').innerHTML = filtered; function removeDuplicates(arr) { // @todo implement }
  27. const unfiltered = [1, 2, 3, 5, 1, 5, 9,

    1, 2, 8]; const filtered = removeDuplicates(unfiltered); // filtered should be equal [1, 2, 3, 5, 9, 8] document.getElementById('answer').innerHTML = filtered; function removeDuplicates(arr) { return arr.filter(...) }
  28. Ducks win!

  29. const unfiltered = [1, 2, 3, 5, 1, 5, 9,

    1, 2, 8]; const filtered = removeDuplicates(unfiltered); // should be [1, 2, 3, 5, 9, 8] document.getElementById('answer').innerHTML = filtered; function removeDuplicates(arr) { const obj = {}; for (const el of arr) { obj[el] = true; } return Object.keys(obj); }
  30. 30 Googling is better, than learning JS

  31. const unfiltered = [1, 2, 3, 5, 1, 5, 9,

    1, 2, 8]; const filtered = removeDuplicates(unfiltered); // filtered should be equal [1, 2, 3, 5, 9, 8] document.getElementById('answer').innerHTML = filtered; function removeDuplicates(arr) { return Array.from(new Set(arr)); }
  32. 32 HAPPY CODING WITH JAVASCRIPT! You can find me at

    twitter as @galk_in Slides are available at speakerdeck.com/galkin or at my site galk.in