Skip to content

Latest commit

 

History

History
120 lines (91 loc) · 3.21 KB

_scratch.md

File metadata and controls

120 lines (91 loc) · 3.21 KB

RFC Email structure

https://stackoverflow.com/a/66551704


Object digging

const isArray = (obj) => Array.isArray(obj);
const isObject = (obj) =>
  typeof obj === "object" && obj !== null && !isArray(obj);
const isNull = (obj) => typeof obj === "object" && obj === null;

const handleArray = (arr, d) => ({
  type: "array",
  value: arr.map((e) => typeFn(e, d)),
});
const handleObject = (obj) => ({
  type: "object",
  value: Object.entries(obj).reduce(
    (a, [k, v]) => ({ ...a, [k]: typeFn(v) }),
    {}
  ),
});
const handleNull = () => ({ type: "null", value: null });
const handleSimple = (obj) => ({ type: typeof obj, value: obj });

const typeFn = (obj) => {
  if (isArray(obj)) return handleArray(obj);
  if (isObject(obj)) return handleObject(obj);
  if (isNull(obj)) return handleNull(obj);

  return handleSimple(obj);
};
const isArray = (obj) => Array.isArray(obj);
const isObject = (obj) =>
  typeof obj === "object" && obj !== null && !isArray(obj);
const isNull = (obj) => typeof obj === "object" && obj === null;

const handleArray = (obj, path) =>
  obj.reduce((a, c, i) => ({ ...a, ...flatAddress(c, `${path}[${i}]`) }), {});
const handleObject = (obj, path) =>
  Object.entries(obj).reduce(
    (a, [k, v]) => ({ ...a, ...flatAddress(v, `${path}.${k}`) }),
    {}
  );
const handleNull = (obj, path) => ({ [path]: { type: "null", value: null } });
const handleSimple = (obj, path) => ({
  [path]: { type: typeof obj, value: obj },
});

const flatAddress = (obj, path = "$") => {
  if (isArray(obj)) return handleArray(obj, path);
  if (isObject(obj)) return handleObject(obj, path);
  if (isNull(obj)) return handleNull(obj, path);

  return handleSimple(obj, path);
};

devtools quick fetch

// devtools quick fetch
const f = (type, ...args) => (middles = args => Promise.resolve(args)) =>
    fetch(...args).then(d => {
        switch(type.toLowerCase()) {
            case "j":
                return d.json()
            case "t":
                return d.text()
            default: // still allows text/json
                return d[type]()
        }
    }).then(middles).then(console.log)

Interview Questions

https://lethain.com/appropriate-programming-problems/

I think what makes good problems to evaluate programming experience of senior and Staff-plus candidates are:

  1. Support simple initial solutions and compounding requirements
  2. Are solvable with a few dozen lines of code
  3. Require algorithmic thinking but not knowing a specific algorithm
  4. Don’t require juggling numerous variables in your head
  5. Does support debugging and evolving the code
  6. Are not domain specific to advantage arbitrary experience
  7. Require writing actual code in language of their choice
  8. Are done in a real code editor

I’m sure there are other criteria that are important, but generally I think those are a good starting point.

Questions:

  • fizzbuzz with APIS
  • queue and limited resource management
  • audio and event handling

Assessing Tech Debt

https://www.npmjs.com/package/jscpd