-
Notifications
You must be signed in to change notification settings - Fork 12
HW3 #17
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?
HW3 #17
Changes from all commits
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,111 @@ | ||
| function splitAndMerge(str, sp) { | ||
| var words = str.split(' '); | ||
| var newWords = []; | ||
| words.forEach(function (word) { | ||
| newWords.push(word.split('').join(sp)) | ||
| }); | ||
| return newWords.join(' '); | ||
| } | ||
|
|
||
| function convert(object) { | ||
| var arr = [] | ||
| for (const key in object) { | ||
| arr.push([key, object[key]]); | ||
|
Contributor
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. @Zorin-Alex Works good. Also you can look at internal method Object.entries |
||
| } | ||
| return arr; | ||
| } | ||
|
|
||
| function toCamelCase(str) { | ||
| var splitString = str.split('-'); | ||
| var newString = []; | ||
| if (splitString.length == 1) { | ||
| splitString = str.split('_'); | ||
|
Contributor
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. @Zorin-Alex Works good. And here also you can use |
||
| } | ||
| for (var i = 0; i < splitString.length; i++) { | ||
| if (i == 0) { | ||
| newString.push(splitString[i]) | ||
| } else { | ||
| newString.push(splitString[i].charAt(0).toUpperCase() + splitString[i].slice(1)); | ||
| } | ||
| } | ||
| return newString.join(''); | ||
| } | ||
|
|
||
| function reverse(str) { | ||
| var words = str.split(' '); | ||
| var newString = []; | ||
| words.forEach(function (word) { | ||
| newString.push(word.split('').reverse().join('')); | ||
| }); | ||
| return newString.join(' '); | ||
|
Contributor
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. @Zorin-Alex Works good. You can use |
||
| } | ||
|
|
||
| function stringExpansion(str) { | ||
| var sets = str.match(/(\d{1}\D{1})|\D/g) | ||
| var newString = []; | ||
| if (!sets || sets.length == 0) { | ||
| return str; | ||
| } | ||
| sets.forEach(function (set) { | ||
| if (set.length == 1) { | ||
| newString.push(set); | ||
| } else { | ||
| for (var i = 0; i < set[0]; i++) { | ||
| newString.push(set[1]); | ||
| } | ||
| } | ||
| }); | ||
| return newString.join(''); | ||
| } | ||
|
|
||
| function largest() { | ||
| var max = arguments[0]; | ||
| for (var i = 1; i < arguments.length; i++) { | ||
| max = max > arguments[i] ? max : arguments[i]; | ||
| } | ||
| return max; | ||
| } | ||
|
|
||
| function smallest() { | ||
| var min = arguments[0]; | ||
| for (var i = 1; i < arguments.length; i++) { | ||
| min = min < arguments[i] ? min : arguments[i]; | ||
| } | ||
| return min; | ||
| } | ||
|
|
||
| function transform(arr) { | ||
| var functions = []; | ||
| function getFunction(arg) { | ||
| var value = arg; | ||
| return function () { return value }; | ||
| } | ||
| arr.forEach(function (arg) { | ||
| functions.push(getFunction(arg)); | ||
| }); | ||
|
|
||
| return functions; | ||
| } | ||
|
|
||
| function sum() { | ||
| return arguments.length == 0 ? 0 : arguments[0] + sum.apply(null, Array.prototype.slice.call(arguments, 1)); | ||
| } | ||
|
|
||
| function countDown(i) { | ||
| setTimeout(function () { | ||
| if (i >= 0) { | ||
| console.log(i); | ||
| countDown(--i); | ||
| } | ||
| }, 1000) | ||
| } | ||
|
|
||
| Function.prototype.myBind = function () { | ||
| var primaryFunc = this; | ||
| var context = arguments[0]; | ||
| var primaryArgs = Array.prototype.slice.call(arguments, 1); | ||
| return function() { | ||
| var args = primaryArgs.concat(Array.prototype.slice.call(arguments)); | ||
| return primaryFunc.apply(context,args); | ||
| } | ||
| } | ||
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.
@Zorin-Alex Works good. Lok at
splitmethod deeper, it can take regexp as an argument, so you can split all the string withsplit(/\s|/))and then join in one string