Skip to content

Instantly share code, notes, and snippets.

@empeje
Last active August 3, 2019 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save empeje/3946e2cbe027254a9e91f6e8a4e12810 to your computer and use it in GitHub Desktop.
Save empeje/3946e2cbe027254a9e91f6e8a4e12810 to your computer and use it in GitHub Desktop.
Interview Vidio
// Problem #1
const displayMulti = (str, repeatTime) => {
const firstThreeLetter = str.substring(0, 3);
const stringToBeDisplayed = firstThreeLetter.length === 3 ? firstThreeLetter : firstThreeLetter.split('').reverse().join('');
console.log(stringToBeDisplayed.repeat(repeatTime));
}
// Problem #2
class PhoneBook {
constructor(log) {
this.log = log;
this.phoneEntries = [];
}
isPhoneNumberUnique(phoneEntry){
const dataMatch = this.phoneEntries.filter(entry => entry.phone === phoneEntry.phone);
return dataMatch.length === 0;
}
addNewPhoneBook(entry) {
if(this.isPhoneNumberUnique(entry)) {
this.phoneEntries = this.phoneEntries.concat(entry);
return 'insert success';
}
return 'duplicate phone number';
}
updatePhoneBookAndLog() {
const phonebookEntries = this.log.split(';');
const addPhoneBookLogs = phonebookEntries
.map(rawEntry => {
const [firstName, lastName, phone] = rawEntry.split(',');
return {firstName, lastName, phone};
})
.map(entry => {
const insertResult = this.addNewPhoneBook(entry);
return {...entry, insertResult};
});
addPhoneBookLogs.map(entry => {
const {firstName, lastName, phone, insertResult} = entry;
console.log(`${firstName} ${lastName} - ${phone} : ${insertResult}`);
})
}
}
const test2 = new PhoneBook('Charlie,Zoe,08123123123;Andre,Xavier,08111222333;Charlie,Xyz,08123123123;Jean,Summers,08001001001')
test2.updatePhoneBookAndLog()

Problem 4

a. What new programming languages / tools have you heard of?

  • 25 Cognitive Bias
  • Elixir
  • Rust
  • Idris
  • Elm
  • Blockchain

b. Which ones are you interested in learning / using?

  • 25 Cognitive Bias
  • Rust
  • Idris, and
  • Elm
  • Blockhain

c. Why?

  • 25 Cognitive Bias, popularize by Charlie Munger (the right hand of Warren Buffet), Charlie brings 25 bias that sync between Pyschology and Economics and also sync with our day to day life as an engineer, learning and applying this, so far makes me better programmer.
  • Rust because it is beatiful that it can reach memory and thread safety without garbage collector!
  • Idris, type driven development
  • Elm, no runtime exception
  • Blockhain, the next internet?

Problem 5

a. Have you written any automated tests for your code? Yes I have!

b. What type / level of tests did you write?

  • Various level,
  • I start my career as end-to-end test developer (they call it Software Development Engineer in Test) when I join Midtrans, and basically I cover automated test for blackbox e2e test for the company's payment system.
  • Then in the same company I also implemented chaos monkey, thus I encourage people to expect the system to fail, I do chaos game day at that time to make engineer understand more about the system they're building.
  • Then when I back to development side of software engineering I wrote unit and integration test, which cover testing basic unit of code like function and class, and integration test which is more high level, like testing the API controller I wrote.
  • For frontend I also create snapshot test and component testing.
  • Manual test.
  • But all that type or level of test must be used by the context, if the problem is we want to go for time to market, doing over testing is not wise, if the problem is buggy code, more chaos monkey game day or bug buster should be done.

c. What test framework or tools did you use?

  • Various frameworks
  • From homebrew creation to ready to use in the market, for me
  • Java: JUnit, WireMock
  • Ruby: RSpec
  • Cucumber
  • JavasScript: @hapi/lab, Mocha, Jest
  • Bash: plain bash testing
  • Python: pytest

Problem 6

Tell us about any project you did that you are proud of, and why you are proud of it. And maybe with some code snippet (~100 lines), or link to Github Gist you wrote for that project.

-- This is PSQL query
SELECT
*
FROM "messages" message
LEFT JOIN "attachments" attachment on message."attachment_id" = attachment."id"
WHERE attachment."mime_type"='video/mp4' AND
message."created_at" >= (NOW() - INTERVAL '3 hours' )
ORDER BY message."created_at" DESC;
-- Basically how index works is we want to increase read (search) speed
-- at the cost of write speed. Why? Basically index will create sorted version of the column
-- so that we can do binary search which generally faster than linear search.
-- Assuming "messages"."id" and "attachments"."id" is in UUID, not auto increment (if its auto incremented,
-- no point of indexing, it is already sorted),
-- it will make a good index because it is the ID and can give us the uniqueness advantages
-- in the context of the query, "attachments"."mime_type" and "messages"."created_at"
-- can be good candidate as well since we use this to give scope to our query
-- But back to basic, before doing any index, in general we want to test our most-frequent query
-- and see if its slow before doing the indexing, so that we can measure how big the performance of the index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment