Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Krivorotova Tatyana/convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* convert */
function convert(obj){
var objKeys = Object.keys(obj);
const res = objKeys.map(function(value){
return [value, obj[value]];
})
console.log(res);
}
obj1 = {name: 'Jeremy', age: 24, role: 'Software Engineer'};
console.log(convert(obj1));
11 changes: 11 additions & 0 deletions Krivorotova Tatyana/countDown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* countDown */
function countDown(k)
{
var i = k;
const timerId = setInterval(function(){
if(i == 0)
clearInterval(timerId);
console.log(i); i--;
}, 1000)
}
countDown(3);
14 changes: 14 additions & 0 deletions Krivorotova Tatyana/largest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* largest */
function largest()
{
var tmp = arguments[0];
for(var j = 0; j < arguments.length; ++j)
{
if(tmp < arguments[j])
{
tmp = arguments[j];
}
}
return tmp;
}
console.log(largest(2, -5, 100, 3));
13 changes: 13 additions & 0 deletions Krivorotova Tatyana/myBind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* myBind */
Function.prototype.myBind = function(context){
var myArguments = Array.prototype.slice.call(arguments, 1),
mybound = this;
return function(){
var myBoundArguments = Array.prototype.slice.call(arguments);
return mybound.apply(context, myBoundArguments)
}
}

function addPropToNumber(number) { return this.prop + number; }
var bound = addPropToNumber.myBind({ prop: 9 });
bound(1)
10 changes: 10 additions & 0 deletions Krivorotova Tatyana/reverseString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* reverseString */
function reverseString(str){
var stringArr = str.split(' ');
stringArr = stringArr.map(function(value){
return value.split('').reverse().join('');
})
stringArr = stringArr.join(' ');
console.log(stringArr);
}
console.log(reverseString(" A fun little challenge! "));
105 changes: 105 additions & 0 deletions Krivorotova Tatyana/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* splitAndMerge */
function splitAndMerge(str, sp){
let wrds = str.split(' '); //Dividing sentence into words
const chars = [];
for(let i = 0; i < wrds.length; ++i)
chars.push(wrds[i].split('').join(sp)); //Dividing words into chars
chars = chars.join(' ');
console.log(chars);
}
console.log(splitAndMerge("Hello World!", ","));
console.log(splitAndMerge("My name is John"," "));
/* convert */
function convert(obj){
let objKeys = Object.keys(obj);
const res = objKeys.map(function(value){
return [value, obj[value]];
})
console.log(res);
}
obj1 = {name: 'Jeremy', age: 24, role: 'Software Engineer'};
console.log(convert(obj1));
/* toCamelCase */
function toCamelCase(str){
str = str.split(/[-|_]/g);
console.log(str);
for(let i = 1; i < str.length; ++i){
str[i] = str[i].charAt(0).toUpperCase() + str[i].slice(1);
}
return str.join('');
}
console.log(toCamelCase("the-stealth-warrior"));
console.log(toCamelCase('The_Stealth_Warrior'));
/* reverseString */
function reverseString(str){
str = str.split(' ');
str = str.map(function(value){
return value.split('').reverse().join('');
})
str = str.join(' ');
console.log(str);
}
console.log(reverseString(" A fun little challenge! "));
/* stringExpansion */
/* largest */
function largest(arr)
{
let numbers = [];
for(let i = 0; i < arguments.length; ++i)
{
numbers[i] = arguments[i];
}
let tmp = numbers[0];
for(let j = 0; j < numbers.length; ++j)
{
if(tmp < numbers[j])
tmp = numbers[j];
}
return tmp;
}
console.log(largest(2, -5, 100, 3));
/* smallest */
function smallest(arr)
{
let numbers = [];
for(let i = 0; i < arguments.length; ++i)
numbers[i] = arguments[i];
let tmp = numbers[0];
for(let j = 0; j < numbers.length; ++j)
{
if(tmp > numbers[j])
tmp = numbers[j];
}
return tmp;
}
console.log(smallest(2, -5, 100, 3));
/* transform */
function transform(arr){
return arr.map(function(value){
return function(){
return value;
}
})
}
const baseArray = [10, 20, 30, 40, 50];
const newArray = transform(baseArray);
newArray[3]();
newArray[4]();
/* sum */
function sum()
{
return arguments.length === 0? 0 : arguments[0] + sum.apply(0, Array.prototype.slice.call(arguments, 1));
}
console.log(sum(2, -5, 100, 3));
/* countDown */
function countDown(k)
{
let i = k;
let timerId = setInterval(function(){
if(i == 0)
clearInterval(timerId);
console.log(i); i--;
}, 1000)
}
countDown(3);
/* myBind */
14 changes: 14 additions & 0 deletions Krivorotova Tatyana/smallest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* smallest */
function smallest()
{
var tmp = arguments[0];
for(var j = 0; j < arguments.length; ++j)
{
if(tmp > arguments[j])
{
tmp = arguments[j];
}
}
return tmp;
}
console.log(smallest(2, -5, 100, 3));
13 changes: 13 additions & 0 deletions Krivorotova Tatyana/splitAndMerge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* splitAndMerge */
function splitAndMerge(str, sp){
var wrds = str.split(' ');
var modifiedWrds = [];
for(let i = 0; i < wrds.length; ++i)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use for, if without brackets - it decreases readability of your code

{
modifiedWrds.push(wrds[i].split('').join(sp));
}
modifiedWrds = modifiedWrds.join(' ');
console.log(modifiedWrds);
}
console.log(splitAndMerge("Hello World!", ","));
console.log(splitAndMerge("My name is John"," "));
15 changes: 15 additions & 0 deletions Krivorotova Tatyana/stringExpansion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* stringExpansion */
function stringExpansion(str){
return str.match(/\d?[A-Za-z]/ig).reduce(function(acc, currItem){
if(!parseInt(currItem))
{
acc.push(currItem);
}
acc.push(currItem[currItem.length-1].repeat(parseInt(currItem)));
return acc;
}, []).join('');
}

console.log(stringExpansion('3D2a5d2f'));
console.log(stringExpansion('3d332f2a'));
console.log(stringExpansion('abcde'));
6 changes: 6 additions & 0 deletions Krivorotova Tatyana/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* sum */
function sum()
{
return arguments.length === 0? 0 : arguments[0] + sum.apply(0, Array.prototype.slice.call(arguments, 1));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm ok with that solution, but maybe better to use here reduce instead of recursion?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, ignore this comment - I didn't see that recursion is the requirement

}
console.log(sum(2, -5, 100, 3));
11 changes: 11 additions & 0 deletions Krivorotova Tatyana/toCamelCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* toCamelCase */
function toCamelCase(str){
var stringArr = str.split(/[-|_]/g);
console.log(stringArr);
for(let i = 1; i < stringArr.length; ++i){
stringArr[i] = stringArr[i].charAt(0).toUpperCase() + stringArr[i].slice(1);
}
return stringArr.join('');
}
console.log(toCamelCase("the-stealth-warrior"));
console.log(toCamelCase('The_Stealth_Warrior'));
12 changes: 12 additions & 0 deletions Krivorotova Tatyana/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* transform */
function transform(arr){
return arr.map(function(value){
return function(){
return value;
}
})
}
const baseArray = [10, 20, 30, 40, 50];
const newArray = transform(baseArray);
newArray[3]();
newArray[4]();