-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtechInterview.js
More file actions
91 lines (68 loc) · 2.22 KB
/
techInterview.js
File metadata and controls
91 lines (68 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Write program, that runs through numbers from 1 to 100.
// For numbers divisible by 3 it writes to console "Tech".
// For numbers divisible by 5 it writes to console "Bakers".
// If the number is divisible by 3 and 5, it only writes to console "Techbakers".
// Otherwise it writes to console given number.
const code = () => {
for (let i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0){
console.log("Techbakers")
}
else if (i % 5 == 0) {
console.log("Bakers")
}
else if (i % 3 == 0) {
console.log("Tech")
}
}
}
// Implement findUser function, which locates user (object) by its id property or null, when the user is not found.
// Tested on user 'u40000' => {id: 'u40000', name: 'user 40000'}
// Tested on user 'u40000000' => null
function code() {
const createUser = (id, name) => {
return { id: id, name: name }
}
const users = []
for (let id = 1; id <= 1e5; id++) {
users.push(createUser('u' + id, 'user ' + id))
}
const findUser = (users) => (id) => {
return users.find((user) => user.id === id) || null
// for (let i = 0; i < users.length; i++) {
// if (users[i].id === id) {
// return users[i]
// }
// }
// return null
}
return findUser(users)
}
// Fix following code to output '$:rm -rf /' and explain your solution.
function code() {
// Edit here
class Process {
constructor(cmd) {
this.cmd = cmd
}
exec() {
console.log(`$: ${this.cmd}`)
}
}
const surprise = new Process('rm -rf /')
setTimeout(() => surprise.exec, 100)
}
// Write a function that returns true if the arguments are an anagram (https://en.wikipedia.org/wiki/Anagram) of each other, otherwise it returns false
// isAnagram('abcd', 'bdca') // true
// isAnagram('bd2', '3db') // false
function code() {
const isAnagram = (a, b) => {
if (a.length !== b.length) {
return false
}
const aString = a.split('').sort().join('')
const bString = b.split('').sort().join('')
return aString === bString
}
return isAnagram
}