-
Notifications
You must be signed in to change notification settings - Fork 12
task 3 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
task 3 #3
Changes from 13 commits
71cccca
17f2f84
fe8a837
256a235
52a4238
3ee0313
ea8ae5b
7b927d8
980e952
ecb87f3
6d40b57
c8b0f88
ef14946
a257ee2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| function countDown(n) { | ||
| for (let i = n; i >= 0; i--) { | ||
|
||
| setTimeout(function() { | ||
| console.log(i); | ||
| }, 1000 + (n - i) * 1000); | ||
| } | ||
| } | ||
|
|
||
| countDown(10); | ||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are methods like
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| 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); | ||
|
|
| 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); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does empty space mean? |
||
|
|
||
| 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(' ') | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| function stringExpansion(str) { | ||
| if (str == "") { | ||
|
||
| 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; | ||
| } | ||
| 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)) |
| 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(''); | ||
| } |
| 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++) { | ||
|
||
| 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]()); | ||
There was a problem hiding this comment.
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