Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle empty array input in selection sort
  • Loading branch information
MayankSharma-2812 committed Jan 25, 2026
commit b135a5156652c5a8ad22324e065a8e8e73f40293
8 changes: 7 additions & 1 deletion Sorts/SelectionSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export const selectionSort = (list) => {
if (!Array.isArray(list)) {
throw new TypeError('Given input is not an array')
}
const items = [...list] // We don't want to modify the original array

if (list.length === 0) {
return []
}

const items = [...list]

const length = items.length
for (let i = 0; i < length - 1; i++) {
if (typeof items[i] !== 'number') {
Expand Down