Skip to main content

Shuffler

readFileToArray

readFileToArray(f) → Promise.<Array.<string>>

Read a file into an array of line strings

Returns: An array of lines

Parameters

NameTypeRequiredDescription
f

The file path

shuffle

shuffle(
  a,
  sort,
  seed,
  check_dupes
) → *

Shuffle an array using the Durstenfeld algorithm

Returns: The same array object, after shuffling

Parameters

NameTypeRequiredDescription
a

An array of strings

sort

First sort alphabetically if true, so the input order does not matter

seed

The order will always be the same for the given string; nil for a random seed

check_dupes

Abort if duplicate is found

shuffleFile

shuffleFile(
  f,
  sort,
  seed,
  check_dupes
) → Promise.<Array.<string>>

Shuffle the lines in a file, print the result, and write it back out to the result of shuffledPath()

Returns: The shuffled lines in an array

Parameters

NameTypeRequiredDescription
f

The file path

sort

see shuffle()

seed

see shuffle()

check_dupes

see shuffle()

writeArrayToFile

writeArrayToFile(
  f,
  a
)

Write an array of strings to a file, one element per line

Parameters

NameTypeRequiredDescription
f

The file path

a

An array of strings