Skip to content
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

code: added Typescript and Javascript examples #196

Merged
merged 31 commits into from
Jan 6, 2023

Conversation

RiverTwilight
Copy link
Contributor

Not sure whether these formats meet the requirement. If everything is okay I will continue to transcribe more:-)

If this PR is related to coding or code translation, please fill out the checklist.

  • I've tested the code and ensured the outputs are the same as the outputs of reference codes.
  • I've checked the codes (formatting, comments, indentation, file header, etc) carefully.
  • The code does not rely on a particular environment or IDE and can be executed on a standard system (Win, macOS, Ubuntu).

Not sure whether these formats meet the requirement. If everything is okay I will continue to transcribe more:-)
@vercel
Copy link

vercel bot commented Jan 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
hello-algo ⬜️ Ignored (Inspect) Jan 6, 2023 at 0:32AM (UTC)

@RiverTwilight
Copy link
Contributor Author

I've finished transcribing time_complexity.js and some codes in the doc, could you review these changes? I will continue work on the typescript if everything goes well. @krahets

Code run result here:
image

@RiverTwilight RiverTwilight changed the title docs: added Typescript and Javascript examples code: added Typescript and Javascript examples Jan 2, 2023
Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

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

Thanks! Please address the comments.

@RiverTwilight
Copy link
Contributor Author

RiverTwilight commented Jan 2, 2023

All addressed @krahets

Typescript code run result:
image

@krahets
Copy link
Owner

krahets commented Jan 2, 2023

All addressed @krahets

Thanks! You can press the Resolve Conversation button after addressing the comments.

Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

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

Some unaddressed comments are found.

@RiverTwilight
Copy link
Contributor Author

Some unaddressed comments are found.

Here

Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

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

Several unaddressed comments in time_complexity.md.

@RiverTwilight
Copy link
Contributor Author

Several unaddressed comments in time_complexity.md.

Oh, I couldn't catch it anymore...as above mentioned I didn't change any text. You may need to check the raw file instead of the code diff.

image

image

Copy link
Contributor

@justin-tse justin-tse left a comment

Choose a reason for hiding this comment

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

Thank you @RiverTwilight for your clear code. It seems good and only has a small flaw.
And lack one part in the time_complexity.md:
=== "JavaScript"
js title="worst_best_time_complexity.js"
=== "TypeScript"
typescript title="worst_best_time_complexity.ts"
Please add it, thank you!

krahets and others added 12 commits January 5, 2023 01:00
Co-authored-by: Justin Tse <xiefahit@gmail.com>
…ity.js

Co-authored-by: Justin Tse <xiefahit@gmail.com>
…ity.ts

Co-authored-by: Justin Tse <xiefahit@gmail.com>
…ity.ts

Co-authored-by: Justin Tse <xiefahit@gmail.com>
Co-authored-by: Justin Tse <xiefahit@gmail.com>
Co-authored-by: Justin Tse <xiefahit@gmail.com>
…ity.ts

Co-authored-by: Justin Tse <xiefahit@gmail.com>
Co-authored-by: Justin Tse <xiefahit@gmail.com>
Co-authored-by: Justin Tse <xiefahit@gmail.com>
Co-authored-by: Justin Tse <xiefahit@gmail.com>
Co-authored-by: Justin Tse <xiefahit@gmail.com>
@RiverTwilight
Copy link
Contributor Author

RiverTwilight commented Jan 5, 2023

@justin-tse @krahets Missing worst_best_time_complexity.js added. Code run results here:

image

@RiverTwilight
Copy link
Contributor Author

Missing worst_best_time_complexity.ts added. Code run results here:

image

Copy link
Contributor

@justin-tse justin-tse left a comment

Choose a reason for hiding this comment

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

Thank you @RiverTwilight for your contribution!
The shuffle method has a little problem, which could not generate the true random data, you could check it in Will It Shuffle?
image
You could check one of the shuffle methods in wiki
Btw, I have updated the code, feel free to check it.
After updated, the random data are:
image
Thank you.

}
// 随机打乱数组元素
for (let i = 0; i < n; i++) {
let r = Math.floor(Math.random() * n);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let r = Math.floor(Math.random() * n);
let r = Math.floor(Math.random() * (i + 1));

/* 查找数组 nums 中数字 1 所在索引 */
function findOne(nums) {
for (let i = 0; i < nums.length; i++) {
if (nums[i] == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (nums[i] == 1) {
if (nums[i] === 1) {

}
// 随机打乱数组元素
for (let i = 0; i < n; i++) {
let r = Math.floor(Math.random() * n);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let r = Math.floor(Math.random() * n);
let r = Math.floor(Math.random() * (i + 1));

/* 查找数组 nums 中数字 1 所在索引 */
function findOne(nums: number[]): number {
for (let i = 0; i < nums.length; i++) {
if (nums[i] == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (nums[i] == 1) {
if (nums[i] === 1) {

krahets and others added 3 commits January 6, 2023 03:14
@RiverTwilight
Copy link
Contributor Author

Thanks very much! @justin-tse The code references in the doc have been updated.

Copy link
Contributor

@justin-tse justin-tse left a comment

Choose a reason for hiding this comment

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

@RiverTwilight Thank you for your contribution.

@krahets krahets merged commit 1f5f7e1 into krahets:master Jan 6, 2023
@krahets krahets added the code Code-related label Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Code-related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants