cmpt315a2mikelee
v1.0.0
Published
functions for assignment 2 of cmpt 315
Downloads
2
Readme
cmpt315a2mikelee
Functions for cmpt 315 assignment 2
Purpose
**BEWARE: This library was published for learning purposes. It is not int Describe the intended intent
Usage
Install it:
npm install leem252-cmpt315a2mikelee
Require it:
const _ = require('leem252-cmpt315a2mikelee');
Call it:
const results = _.findNaNIndex(Number[])
const results = _.biggestLoser(Object[])
const results = _.countNumberOfArrays(Array)
const results = _.isArrayFactorChain(Number[])
const results = _.participants(Object[])
const results = _.winnersObject(Object[])
''
Documentation
The following functions are currently implemented:
findNaNIndex(Number[])
: This function loops through an array of numbers and NaN and pushes the index of each NaN found into a array called nanArray
biggestLoser(Object[])
: This function calculates the player with the most loser_points by taking in an array
of match objects as a parameter. This function calculates the total amount of loser_points for each player
by subtracting the loser_points of the match object from the winning player and adds the loser_points
of the match object to the losing player. The function then finds the player with the most loser_points by using the reduce method
and returns the name of the player with the most loser points
countNumberOfArrays(Array)
: This function takes an array and counts the number of arrays that are within it using an arrayCounter variable that is
incremented by 1 everytime it finds an array inside the given array
isArrayFactorChain(Number[])
: This function takes data(an array of numbers) and iterates through the array,
the function uses the modulo operator to check if an array of numbers will form a factor chain
by seeing if each number will evenly divide the next number
participants(Object[])
: This function creates an array of player names and loops through the matches array
it pushes all names from the winner and loser of each match, if they have not been
added to the namesArray already, so that there are no duplicate names
winnersObject(Object[])
: This function creates an array of all players using the participants function
and then creates a new winningPlayers object where the key is the player name, value is an empty array
it then loops through each match and pushes the loser name to the winningPlayer in the winningPlayers array