Skip to content

London | 26-ITP-May | Alex Jamshidi | Sprint 1 | Coursework#1314

Open
Alex-Jamshidi wants to merge 13 commits into
CodeYourFuture:mainfrom
Alex-Jamshidi:coursework/sprint-1
Open

London | 26-ITP-May | Alex Jamshidi | Sprint 1 | Coursework#1314
Alex-Jamshidi wants to merge 13 commits into
CodeYourFuture:mainfrom
Alex-Jamshidi:coursework/sprint-1

Conversation

@Alex-Jamshidi
Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Completed solutions to sprint 1 coursework

@Alex-Jamshidi Alex-Jamshidi added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Structuring-And-Testing-Data The name of the module. labels May 11, 2026
@illicitonion illicitonion added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 15, 2026
Copy link
Copy Markdown
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

LGTM - I'll mark this as complete, but please do think about the comments I've left :)

const lastDotIndex = filePath.lastIndexOf(".");

// https://www.google.com/search?q=slice+mdn No newline at end of file
const dir = filePath.slice(1, lastSlashIndex);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I realise the diagram above is a bit ambiguous, but the dir actually includes the leading / as well


// https://www.google.com/search?q=slice+mdn No newline at end of file
const dir = filePath.slice(1, lastSlashIndex);
const ext = filePath.slice(lastDotIndex);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This works for this particular path.

What would happen if I gave you a filePath that didn't contain a . at all? What would you expect it to return? What will your solution return?

// I can make a hypothesis that this returns a random number of some kind, hence the inconsistent result

// Let's find out...
// Code in inner-most brackets is evaluated first
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not quite, actually - it doesn't matter here, but the Math.random() will actually be evaluated before the inner parens.

The order of execution is generally top-to-bottom, left-to-right, with a few exceptions:

  • When we call a function, we evaluate the arguments left-to-right before we can call the function (so we need to evaluate Math.random() * (maximum minimum + 1) before we can call Math.floor`).
  • Things in parentheses get evaluated when we hit the opening parenthesis. So 1 + (2 * 3) will evaluate 1, then evaluate (2 * 3) before it does the 1 + (3).

The point of the parentheses here is to say "do maximum - minimum before *", not "do maximum - minimum before Math.random()" :)

// The function Math.floor appears to be rounding down
// Checking the documentation, this is true, it returns the largest integer <= the given number

// Therefore Math.floor(Math.random() * (maximum - minimum + 1)) must give random numbers between 0 and 99
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One precision thing here - when talking about ranges, we'd generally describe whether the bounds are inclusive of exclusive. Here "between 0 and 99" it isn't clear whether that includes 0 or starts from 1. I'd generally write this "between 0 and 99, inclusive" (or in other contexts, perhaps "between 0 (inclusive) and 100 (exclusive)")

@illicitonion illicitonion added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Structuring-And-Testing-Data The name of the module. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants