This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isPangram(string: String) -> Bool { | |
let alphabet = "abcdefghijklmnopqrstuvwxyz" | |
let lowerCaseString = string.lowercased() | |
for letter in alphabet { | |
if !lowerCaseString.contains(letter) { | |
return false | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if a string is a Pangram. | |
* | |
* @param {string} string - The string to be checked. | |
* @return {boolean} Returns true if the string is a pangram, false otherwise. | |
*/ | |
const isPangram = (string) => { | |
const alphabet = "abcdefghijklmnopqrstuvwxyz" | |
const lowerCaseString = string.toLowerCase() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Removed the localeCompare function call | |
// Replaced it with a more efficient comparison using the less-than and greater-than operators. | |
// This avoids the overhead of string comparison and should make the function faster. | |
/** | |
* Sorts an array of objects alphabetically based on a specified getter function. | |
* | |
* @param {Array} arr - The array to be sorted. | |
* @param {Function} getter - The getter function used to retrieve the value to compare. | |
* @param {string} [order="asc"] - The order in which to sort the array. Default is "asc" (ascending). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - Use the `split()` method to convert the string `str` into an array of characters. | |
// - Use the `sort()` method with a compare function to sort the characters in the array. | |
// - Use the `join()` method to recombine the sorted characters into a string. | |
/** | |
* Sorts the characters in a string in ascending order. | |
* | |
* @param {string} str - The string to sort. | |
* @return {string} The sorted string. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instead of using an object with item and index properties, used an array with [item, index] values. | |
// This reduces the memory footprint and improves performance. | |
// Modified the .map() and .sort() functions to work with the array of [item, index] pairs. | |
// Used destructuring assignment in the .map() function to extract only the item value from each pair. | |
/** | |
* Sorts an array in a stable manner using a custom compare function. | |
* | |
* @param {Array} arr - The array to be sorted. | |
* @param {Function} compare - The compare function used to determine the order of elements. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func weightedAverage(nums: [Double], weights: [Double]) -> Double { | |
var sum = 0.0 | |
var weightSum = 0.0 | |
for i in 0..<nums.count { | |
sum += nums[i] * weights[i] | |
weightSum += weights[i] | |
} | |
return sum / weightSum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// | |
/// # Arguments | |
/// | |
/// * `nums`: | |
/// * `weights`: | |
/// | |
/// returns: f64 | |
/// | |
/// # Examples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if one set is a super set of another set. | |
* | |
* @param {Array} a - The first set. | |
* @param {Array} b - The second set. | |
* @return {boolean} Returns true if the first set is a super set of the second set, otherwise returns false. | |
*/ | |
function superSet(a, b) { | |
const sA = new Set(a) | |
const sB = new Set(b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION replaceAccentChar (@source as varchar(255)) | |
RETURNS varchar(255) AS | |
BEGIN | |
declare @charList as varchar(20) | |
declare @temp as varchar(255) | |
declare @t asint | |
set @temp = @source | |
set @charList = 'aeioucn' |