Skip to content

Instantly share code, notes, and snippets.

@skarankevich
Last active November 19, 2020 09:53
Show Gist options
  • Save skarankevich/f429e5b8c416981ccff1 to your computer and use it in GitHub Desktop.
Save skarankevich/f429e5b8c416981ccff1 to your computer and use it in GitHub Desktop.
FE Test
(function() {
console.log(abc);
var abc = "abc";
console.log(myFunc());
function myFunc() {
var def = abc + 'def';
return def;
}
})();
function loop() {
for (var i = 0; i < 5; i++) {
setTimeout(function() {
console.log(i);
}, i * 1000);
}
}
loop();
var assert = require('chai').assert;
var greetings = (function createMessages() {
var messages = [];
for (var i = 0; i < 10; i++) {
messages.push(function () {
return `Hi! I am ${i}`;
});
}
return messages;
})();
// Let's try
try {
assert.equal(greetings[0](), 'Hi! I am 0');
assert.equal(greetings[7](), 'Hi! I am 7');
console.info('OK');
} catch (e) {
console.warn(e.message);
}
(function() {
console.log(1);
setTimeout(function() {
console.log(2);
}, 1000);
setTimeout(function() {
console.log(3);
}, 0);
console.log(4);
})();
// const intersection = () => {};
const firstInput = [9, 2, 3, 5, 8, 9];
const secondInput = [3, 5, 7];
const output = intersection(firstInput, secondInput);
const output = [3, 5];
// Array.prototype.map
const persons = [
{
id: 1,
name: "John Smith",
},
{
id: 2,
name: "Sam Nilson",
}
];
function transformPersons(persons) {
...
}
console.log(transformPersons(persons));
// [{
// id: 1,
// firstName: "John",
// lastName: "Smith"
// }, ...]
const assert = require('chai').assert;
function getOddNumbers(numbers) { // odd numbers
return [];
}
// Let's try
try {
assert.deepEqual(getOddNumbers([ 1, 2, 3, 4 ]), [ 1, 3 ]);
assert.deepEqual(getOddNumbers([ 2, 4, 6, 8 ]), []);
assert.deepEqual(getOddNumbers([ 4, 6, 7, 13 ]), [ 7, 13 ]);
console.info('OK');
} catch (e) {
console.warn(e.message);
}
function func() {
this.name = "John";
}
const a = func(); // a? this?
const b = new func(); // b? this?
const c = {
name: "Sam", // do not modify
sayName: function () {
console.log(this.name);
}
}
const d = ...;
d(); // => "John"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment