You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * capitalizeFirstWord * * - Takes a string and capitalizes the first word. * - For example 'the great escape' => 'The great escape' * * @param {string} string The string to modify * @returns {string} The string with the first word capitalized. */exportfunctioncapitalizeFirstWord(string){returnstring.charAt(0).toUpperCase()+string.slice(1);}
Capitalize
/** * capitalize * * - Takes a string and capitalize the first letter of each word. * - For example 'the great escape' => 'The Great Escape' * * @param {string} string The string to modify * @returns {string} The string with each word capitalized. */exportfunctioncapitalize(string){letwords=[];string.split(' ').forEach((word)=>{words.push(capitalizeFirstWord(word));});returnwords.join(' ');}
Random array element
/** * Returns a random element from a given list */functionrandomSelect(array){constrandomIndex=Math.floor(Math.random()*array.length);returnarray[randomIndex];}export{randomSelect};
Random boolean
/** * Returns a random boolean */functionrandomBoolean(){returnMath.random()>=0.5;}export{randomBoolean};
Check if all values in array of arrays are equal
/** * Checks if all values in an array of arrays are the same. */functioncheckValuesEqual(array){lets=newSet([].concat(...array));returns.size===1;}/** * Checks if all values in array of arrays are equal to a given value. * * let arrays = [[true, true, true], [true, true, true], [true]]; */functioncheckValuesEqualTo(array,value){lets=newSet([].concat(...array));return(s.size===1&&s.has(value));}/** * Checks if all values in array of arrays are equal to a given value. * * let arrays = [[true, true, true], [true, true, true], [true]]; */functioncheckValuesEqualTo(array,value){returnarray.every(row=>row.every(col=>col===value));}
Random RGB color
/** * Generate a random RGB color for CSS purposes * * Returns a string css rgb value like: rgb(255,120,10) */functionrandomRGB(){// Generate a random number between 0 and given number (inclusive)functionrandom(n){returnMath.floor(Math.random()*(n+1));}return`rgb(${random(255)},${random(255)},${random(255)})`;}console.log(randomRGB());// rgb(104,118,229)