Frage im Vorstellungsgespräch bei Dream11

Write a function named 'Once' which accept another function 'sum' ( function sum(a,b){return a+b;}) and return a function and when this returned function called, it should return result of 'sum' (i.e a+b ) passed to 'Once' function. And every time it should return same result that got at first call .

Antworten zu Vorstellungsgespräch

Anonym

27. Aug. 2019

var Once = function(sum){ let result ; return function (...args){ if(result) return result; result = sum(...args); return result; } }

4

Anonym

2. Jan. 2019

flatten multidimensional array in one array - var a = [1,2,[3,4],5,[6,[7,8]]];

3