This repository contains just answers.
bcherny / frontend-interview-questions Goto Github PK
View Code? Open in Web Editor NEWAnswers for https://borischerny.com/javascript/%22functional/programming%22/2017/06/09/Frontend-Interview-Questions.html
Answers for https://borischerny.com/javascript/%22functional/programming%22/2017/06/09/Frontend-Interview-Questions.html
This repository contains just answers.
isBalanced('}{'); // true
I guess it depends on what you call balanced ๐
Could test that count >= 0
before count--
, return false
if not.
URL links to the question doesn't load.
if you try to call it with let s = assignDeep({a:1}, {b: new Date()})
, you get an object: {a:1, b: {}}, rather than {a:1, b: date object}.
The reason lies in:
function isObject(a) { return typeof a === 'object' && a !== null}
if you try to call it as: isObject(new Date()), it returns true, therefore it going to be treated the date as an iterable object, I mean, it recursively call the assignDeep method on the date object.
however, during my tests, function isObject(a) { return typeof a === 'object' && a !== null&& Object.keys(a).length>0
, can be a good solution to check if this source[key] is an interable object.
Hello,
Thanks for putting this together, I was just browsing and noticed a bug in implementation of isPrime. It returns wrong results.
Try:
isPrime(9); // -> true
isPrime(21); // -> true
isPrime(25); // -> true
And none of these is prime. It will return true for any odd number, as you are skipping all of the odd number dividers (counter has a value of 2 + (n * 2)
) on the line #17
for (let i = 2; i < Math.ceil(Math.sqrt(n)); i += 2) {
if (n % i === 0) {
return false
}
}
You just need to increment by 1 not by 2.
Cheers!
Current implementation
function reverse(string) {
let index = string.length - 1
let result = ''
while (index > -1) {
result += string[index]
index--
}
return result
}
same as this one (short and popular one)
function reverse(string) {
return string.split('').reverse().join('');
}
Both wont work with with Unicode chars which length is more than 16 bit (surrogate pairs).
Because both split('')
and string[i]
will address characters by 16 bit blocks, and so destroy Unicode pairs.
Ex.:
reverse('abc ๐') // Error: expected '๏ฟฝ๏ฟฝ cba' to equal '๐ cba'
Solution is es6 string[Symbol.iterator]
via destructuring, which takes Unicode chars into account (proof):
function reverse(str) {
return [...str].reverse().join('');
}
Probably you want to keep answers as transparent as possible and split().reverse().join()
is too hack-ish for educational purposes. But maybe you can mention Unicode issue in the comment above the solution for people to know. Cheers.
Original question
let tree = new BinarySearchTree
tree.add(1, 2, 3, 4)
tree.add(5)
tree.has(2) // true
tree.has(5) // true
tree.remove(3) // undefined
tree.size() // 3
Should be tree.size() // 4
(total number of nodes)
Or maybe tree.depth() // 3
(highest distance from root, in case it is not self-balancing BST)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.