Skip to content

Commit

Permalink
Merge branch 'main' into patch-6
Browse files Browse the repository at this point in the history
  • Loading branch information
sammygrey authored Jan 13, 2025
2 parents 2aa1188 + ef6a929 commit 23840dc
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 153 deletions.
2 changes: 1 addition & 1 deletion content/en-us/luau/metatables.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Here's the list of available metamethods:
</tr>
<tr>
<td>__mul(table, value)</td>
<td>The * mulitplication operator.</td>
<td>The * multiplication operator.</td>
</tr>
<tr>
<td>__div(table, value)</td>
Expand Down
24 changes: 12 additions & 12 deletions content/en-us/luau/queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ function Queue.new<T>(): Queue<T>
end

-- Check if the queue is empty
function Queue.IsEmpty<T>(self: Queue<T>)
function Queue.isEmpty<T>(self: Queue<T>)
return self._first > self._last
end

-- Add a value to the queue
function Queue.Enqueue<T>(self: Queue<T>, value: T)
function Queue.enqueue<T>(self: Queue<T>, value: T)
local last = self._last + 1
self._last = last
self._queue[last] = value
end

-- Remove a value from the queue
function Queue.Dequeue<T>(self: Queue<T>): T
if self:IsEmpty() then
function Queue.dequeue<T>(self: Queue<T>): T
if self:isEmpty() then
error("Cannot dequeue from empty queue")
end

Expand All @@ -96,27 +96,27 @@ local Queue = require(ReplicatedStorage:WaitForChild("Queue"))
local myQueue = Queue.new()

-- Add some values to the queue
myQueue:Enqueue(5)
myQueue:Enqueue(10)
myQueue:Enqueue(15)
myQueue:enqueue(5)
myQueue:enqueue(10)
myQueue:enqueue(15)

-- myQueue = { 5, 10, 15 }

-- Remove one value from the queue
local first = myQueue:Dequeue()
local first = myQueue:dequeue()
print("The first value added to the queue was", first)

-- myQueue = { 10, 15 }

-- Add more values to the queue
myQueue:Enqueue(20)
myQueue:Enqueue(25)
myQueue:Enqueue(30)
myQueue:enqueue(20)
myQueue:enqueue(25)
myQueue:enqueue(30)

-- myQueue = { 10, 15, 20, 25, 30 }

-- Remove another value from the queue
local second = myQueue:Dequeue()
local second = myQueue:dequeue()
print("The second value added to the queue was", second)

-- myQueue = { 15, 20, 25, 30 }
Expand Down
24 changes: 12 additions & 12 deletions content/en-us/luau/stacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ function Stack.new()
end

-- Check if the stack is empty
function Stack:IsEmpty()
function Stack:isEmpty()
return #self._stack == 0
end

-- Put a new value onto the stack
function Stack:Push(value)
function Stack:push(value)
table.insert(self._stack, value)
end

-- Take a value off the stack
function Stack:Pop()
if self:IsEmpty() then
function Stack:pop()
if self:isEmpty() then
return nil
end

Expand All @@ -57,21 +57,21 @@ local s = Stack.new()

-- Change the stack Resulting stack Output

s:Push(1) -- {1}
s:push(1) -- {1}

s:Push(5) -- {1, 5}
s:push(5) -- {1, 5}

s:Push(10) -- {1, 5, 10}
s:push(10) -- {1, 5, 10}

print(s:Pop()) -- {1, 5} 10
print(s:pop()) -- {1, 5} 10

print(s:Pop()) -- {1} 5
print(s:pop()) -- {1} 5

s:Push(20) -- {1, 20}
s:push(20) -- {1, 20}

print(s:Pop()) -- {1} 20
print(s:pop()) -- {1} 20

print(s:Pop()) -- {} 1
print(s:pop()) -- {} 1
```

<Alert severity="warning">
Expand Down
52 changes: 26 additions & 26 deletions content/en-us/luau/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ To create a dictionary table, define each **key** followed by `=` and the **valu

```lua
local testDictionary = {
FruitName = "Lemon",
FruitColor = "Yellow",
Sour = true
fruitName = "Lemon",
fruitColor = "Yellow",
sour = true
}
```

Expand All @@ -153,7 +153,7 @@ The keys for dictionaries can be numbers, strings, and objects. For example, a k
local part = Instance.new("Part")

local testDictionary = {
PartType = "Block",
partType = "Block",
[part] = true
}
```
Expand All @@ -166,11 +166,11 @@ To read from a dictionary, add a pair of brackets after its reference and specif
local part = Instance.new("Part")

local testDictionary = {
PartType = "Block",
partType = "Block",
[part] = true
}
-- Include quotes for string keys
print(testDictionary["PartType"]) -- Block
print(testDictionary["partType"]) -- Block
-- Omit quotes for non-string keys
print(testDictionary[part]) -- true
```
Expand All @@ -181,20 +181,20 @@ To define or rewrite the value of a new or existing dictionary key, declare the

```lua
local testDictionary = {
FruitName = "Lemon",
Sour = true
fruitName = "Lemon",
sour = true
}

-- Change value of existing keys
testDictionary["FruitName"] = "Cherry"
testDictionary["Sour"] = false
testDictionary["fruitName"] = "Cherry"
testDictionary["sour"] = false

-- Insert new key-value pair
testDictionary["FruitCount"] = 10
testDictionary["fruitCount"] = 10

print(testDictionary["FruitName"]) -- Cherry
print(testDictionary["Sour"]) -- false
print(testDictionary["FruitCount"]) -- 10
print(testDictionary["fruitName"]) -- Cherry
print(testDictionary["sour"]) -- false
print(testDictionary["fruitCount"]) -- 10
```

### Iterating over Dictionaries
Expand All @@ -203,19 +203,19 @@ To iterate over a dictionary, use the global `pairs()` function in a `for` loop:

```lua
local testDictionary = {
FruitName = "Lemon",
FruitColor = "Yellow",
Sour = true
fruitName = "Lemon",
fruitColor = "Yellow",
sour = true
}

for key, value in pairs(testDictionary) do
print(key, value)
end

--[[ Resulting output:
FruitName Lemon
Sour true
FruitColor Yellow
fruitName Lemon
sour true
fruitColor Yellow
]]
```

Expand All @@ -229,19 +229,19 @@ To remove or erase a key-value pair from a dictionary, set its value for a key t

```lua
local testDictionary = {
FruitName = "Lemon",
FruitColor = "Yellow",
Sour = true
fruitName = "Lemon",
fruitColor = "Yellow",
sour = true
}

testDictionary["Sour"] = nil
testDictionary["sour"] = nil

for key, value in pairs(testDictionary) do
print(key, value)
end
--[[ Resulting output:
FruitName Lemon
FruitColor Yellow
fruitName Lemon
fruitColor Yellow
]]
```

Expand Down
Loading

0 comments on commit 23840dc

Please sign in to comment.