Skip to content
Open
Show file tree
Hide file tree
Changes from 13 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
9 changes: 9 additions & 0 deletions IVAN_MARAKHOVSKII/convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function convert(hash) {
const keys = Object.keys(hash);
const result = []
for (let i = 0; i < keys.length; i++) {
result.push([keys[i],hash[keys[i]]]);
}
return result;
Copy link

Choose a reason for hiding this comment

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

You could also use Object.entries


}
9 changes: 9 additions & 0 deletions IVAN_MARAKHOVSKII/countDown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function countDown(n) {
for (let i = n; i >= 0; i--) {
Copy link

Choose a reason for hiding this comment

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

Pretty much fine, but do you know another solution to the task without let?

setTimeout(function() {
console.log(i);
}, 1000 + (n - i) * 1000);
}
}

countDown(10);
14 changes: 14 additions & 0 deletions IVAN_MARAKHOVSKII/largest-smallest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function largest(){
let max = arguments[0];
for (let i = 1 ; i < arguments.length ; i++){
if (arguments[i] > max ) max = arguments[i]
}
return max
}
function smallest(){
let min = arguments[0];
for (let i = 1 ; i < arguments.length ; i++){
if (arguments[i] < min ) min = arguments[i]
}
return min
Copy link

Choose a reason for hiding this comment

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

There are methods like .largest and .smallest that could be used fir simplicity

Copy link
Author

Choose a reason for hiding this comment

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

it's undefined when i'm trying to get arguments.smallest() or arguments.smallest

}
17 changes: 17 additions & 0 deletions IVAN_MARAKHOVSKII/myBind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Function.prototype.myBind = function(context) {
const f = this;
let args = [].slice.call(arguments,1)
return function() {
args = args.concat([].slice.call(arguments))
return f.apply(context, args);
};
};

function test(a, b) {
console.log(this);
console.log(a + b);
}

const g = test.myBind("context",2);
g(3);

12 changes: 12 additions & 0 deletions IVAN_MARAKHOVSKII/splitAndMerge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function splitAndMerge(str, spl) {
const ans = str.split(" ");
if (!ans[0]) {
// return for space-only string
return "";
}
ans.forEach(function(item, index) {
ans[index] = item.split("").join(spl);
});
return ans.join(spl);
}
Copy link

Choose a reason for hiding this comment

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

Just a note
According to the description - your words should be separated by empty space, not separator you pass in

Copy link
Author

Choose a reason for hiding this comment

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

What does empty space mean?
from description : "... and then divide each word into characters(Use separator empty string);"


7 changes: 7 additions & 0 deletions IVAN_MARAKHOVSKII/string-reverse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function stringReverse(str){
str = str.split(' ')
for (let i = 0 ; i < str.length ; i++){
str[i] = str[i].split('').reverse().join('')
}
return str.join(' ')
}
30 changes: 30 additions & 0 deletions IVAN_MARAKHOVSKII/stringExpansion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function stringExpansion(str) {
if (str == "") {
Copy link

Choose a reason for hiding this comment

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

Avoid using non strict comparisons

return "";
}


let ans = "";
for (let i = 0; i < str.length; i++) {
const char = str.charAt(i);

// index on char and prev is a number
if (i !== 0 && !+char && +str.charAt(i - 1)) {
const number = +str.charAt(i - 1);

for (let j = 0; j < number; j++) {
ans += char;
}
}
// index in char and prev is a char
if (i !== 0 && !+char && !+str.charAt(i - 1)) {
ans += char;
}
// first char
if (!+char && i == 0) {
ans += str.charAt(0);
}
}

return ans;
}
10 changes: 10 additions & 0 deletions IVAN_MARAKHOVSKII/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function sum(){
if (!arguments.length){
return 0
}
else {
return arguments[0] + sum.apply(null,[].slice.call(arguments,1))
}
}

console.log(sum(1,3,5,7))
14 changes: 14 additions & 0 deletions IVAN_MARAKHOVSKII/to-camel-case.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function toCamelCase(str){
let sep;
if (str.indexOf('-') !== -1){
sep = '-'
}else{
sep = '_'
}

str = str.split(sep);
for (let i = 1 ; i < str.length ; i ++){
str[i] = str[i].charAt(0).toUpperCase() + str[i].substring(1);
}
return str.join('');
}
14 changes: 14 additions & 0 deletions IVAN_MARAKHOVSKII/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function transform(arr) {
for (let i = 0; i < arr.length; i++) {
Copy link

Choose a reason for hiding this comment

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

Just a note, you could use map to transform array

let value = arr[i];
arr[i] = function() {
return value;
};
}
return arr;
}

const baseArray = [10, 20, 30, 40, 50];
const newArray = transform(baseArray);
console.log(newArray[3]()); // should return 40
console.log(newArray[4]());