Skip to content

Instantly share code, notes, and snippets.

View ukhlivanov's full-sized avatar

Sergey Ukhlivanov ukhlivanov

  • Philadelphia, PA
View GitHub Profile
@ukhlivanov
ukhlivanov / ThinkFul-Strings(shouter)
Last active April 28, 2018 20:48
ThinkFul-Strings
function shouter(whatToShout) {
// your code here
return whatToShout.toUpperCase() + "!!!";
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
function celsToFahr(celsTemp) {
// your code here
return celsTemp*1.8+32;
}
function fahrToCels(fahrTemp) {
// your code here
return (fahrTemp-32)*1.8;
}
function main() {
try{
doAllTheThings();
}
catch(e){
console.error(e);
reportError(e);
}
}
function makeList(item1, item2, item3) {
// your code here
const arr=[item1,item2,item3];
return arr;
}
/* From here down, you are not expected to
understand.... for now :)
@ukhlivanov
ukhlivanov / ThinkFul-Arrays(Filter)
Created April 30, 2018 01:12
ThinkFul-Arrays 2
function shortWords(array) {
// your code goes here
const myArray = array.filter(word => word.length < 5);
return myArray;
}
/* From here down, you are not expected to
understand.... for now :)
function fizzBuzz(countTo) {
// your code here
const arr=[];
for(let i=1; i<=countTo; i++){
if((i%3 === 0) && (i%5 === 0)){
arr.push("fizzbuzz");
} else if(i%3 === 0){
arr.push("fizz");
}else if(i%5 === 0){
What is scope? Your explanation should include the idea of global vs. local scope.
Scope refers to the visibility of variables. Global variable will be avialable everywhere in program. The local variable will only be available in the code block where it was defined (for example: class or function). When you define a variable in a function that has the same name as a variable in the global scope, the local variable will take precedence over the global one.
Why are global variables avoided?
Global variables are hard to use together with other developers. A global variable can be changed to any part of the program and therefore it is difficult to control it especially in a large application.
Explain JavaScript's strict mode.
When strict mode is enabled all variables should be declared(for example let myVar="myVar"), for variables without declaration error will be triggered. The command "use strict" can be put at the top of file to enforce strict mode, or at the top of functionб, in this case, strict mode will
@ukhlivanov
ukhlivanov / Create
Created May 3, 2018 18:39
ThinkFul-Objects
function createMyObject() {
// your code here
const myObject={
foo: 'bar',
answerToUniverse:42,
'olly olly':'oxen free',
sayHello: function(){
return 'hello';
},
};
@ukhlivanov
ukhlivanov / Find by id
Created May 4, 2018 01:36
ThinkFul-Objects
// you can pass in `scratchData` to test out `findByid`
// your function
const scratchData = [
{ id: 22, foo: 'bar' },
{ id: 28, foo: 'bizz' },
{ id: 19, foo: 'bazz' },
];
function findById(items, idNum) {
// your code here
@ukhlivanov
ukhlivanov / mostFrequentWord
Created May 4, 2018 04:11
ThinkFul(read code)
function getTokens(rawString) {
// Returns array of strings, with lower case, spaces and ,!.";:- - these simbols will be deleted
//regardless of how many times they were repeated and will be removed any falsy items from an array
// the array will be sorted alphabetically. As a result, an array of words is returned in the alphabetical order.
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort();
}
function mostFrequentWord(text) {