Skip to content

Commit 427e7e4

Browse files
committed
Add code for test in interview
1 parent af86247 commit 427e7e4

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

javascript/src/find_triplet.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
// - Write a function that returns a triplet of numbers from the supplied array,
3+
// with a sum equal to a specific integer.
4+
5+
const array = [4, 1, 9, 8, 5, 2, 3, 23, 50, 22, 19, 10];
6+
const int = 35;
7+
8+
// console.log(find_triplet(array,int)) // [ 10, 22, 3 ]
9+
// console.log(find_triplet(array,int)) // null
10+
11+
const find_triplet = (array, sumToCheck) => {
12+
array.sort((a,b) => a - b);
13+
const arrayLength = array.length;
14+
let left, right;
15+
16+
for (let index = 0; index < arrayLength - 2; index++) {
17+
left = index + 1;
18+
right = arrayLength - 1;
19+
20+
while (left < right) {
21+
const value = array[index];
22+
const leftValue = array[left];
23+
const rightValue = array[right];
24+
25+
if (value + leftValue + rightValue === sumToCheck) {
26+
return [value, leftValue, rightValue];
27+
}
28+
else if (value + leftValue + rightValue < sumToCheck)
29+
left++;
30+
else
31+
right--;
32+
}
33+
}
34+
35+
// Not found
36+
return [];
37+
}
38+
39+
console.log(find_triplet(array, int));

javascript/src/generator_testing.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function* gen() {
2+
yield 10;
3+
yield 20;
4+
yield 30;
5+
yield 40;
6+
}
7+
8+
const iterator = gen();
9+
10+
for (let index = 0; index < 5; index++) {
11+
console.log(iterator.next());
12+
}

javascript/src/interviewing.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const nullValue = null;
2+
console.log(typeof nullValue);
3+
4+
console.log(typeof 234567890123456789012345678901234567890n);
5+
6+
hoistedVariable = 3;
7+
console.log(hoistedVariable); // outputs 3 even when the variable is declared after it is initialized
8+
var hoistedVariable;
9+
10+
try {
11+
hoistedVariable2 = 3;
12+
console.log(hoistedVariable2); // outputs 3 even when the variable is declared after it is initialized
13+
let hoistedVariable2;
14+
} catch (error) {
15+
console.log('hoistedVariable2 does not support hosting!')
16+
}
17+
18+
let y = 1234
19+
const x = y
20+
y = 4444
21+
console.log('primitive values');
22+
console.log('y:', y);
23+
console.log('x: ', x);
24+
25+
const obj1 = {
26+
name: 'objecter'
27+
};
28+
const obj2 = obj1;
29+
console.log('obj1', obj1);
30+
console.log('obj2', obj2);
31+
obj1.title = "developer";
32+
console.log('obj1', obj1);
33+
console.log('obj2', obj2);
34+
35+
(function () {
36+
console.log('IIFE');
37+
})();
38+
39+
const pattern = {
40+
name: "joahn",
41+
title: "dev",
42+
phone: 34445000,
43+
address1: "Aveniue 1",
44+
address2: "Aveniue 2"
45+
}
46+
47+
const { name, title, phone, ...address } = pattern;
48+
console.log('pattern', address);
49+

0 commit comments

Comments
 (0)