Skip to content

Instantly share code, notes, and snippets.

View ChousinRahit's full-sized avatar

K Chousin Rahit ChousinRahit

  • ThinkJs
  • Bengaluru
View GitHub Profile
// Convert camelCase to snake_case
// Create a function that takes a string of words (or just one word) and converts each word from camelCase to snake_case.
// Examples
// camelToSnake("magicCarrots") ➞ "magic_carrots"
// camelToSnake("greatApples for aSmellyRhino") ➞ "great_apples for a_smelly_rhino"
// camelToSnake("thatsGreat") ➞ "thats_great"
// From A to Z
// Given a string indicating a range of letters, return a string which includes all the letters in that range,
// including the last letter.Note that if the range is given in capital letters, return the string in capitals also!
// Examples
// gimmeTheLetters("a-z") ➞ "abcdefghijklmnopqrstuvwxyz"
// gimmeTheLetters("h-o") ➞ "hijklmno"
// Split String by Identical Characters
// Create a function that splits a string into an array of identical clusters.
// Examples
// splitGroups("555") ➞ ["555"]
// splitGroups("5556667788") ➞ ["555", "666", "77", "88"]
// splitGroups("aaabbbaabbab") ➞ ["aaa", "bbb", "aa", "bb", "a", "b"]
// Find the Unique Letters
// Create a function that takes a string and returns an array of the letters that occur only once.
// findLetters("monopoly") ➞ ["m", "n", "p", "l", "y"]
// findLetters("balloon") ➞ ["b", "a", "n"]
// findLetters("analysis") ➞ ["n", "l", "y", "i"]
// Replacing Letters with Hashes
// Write a function that replaces all letters within a specified range with the hash symbol #.
// Examples
// replace("abcdef", "c-e") ➞ "ab###f"
// replace("rattle", "r-z") ➞ "#a##le"
// replace("microscopic", "i-i") ➞ "m#croscop#c"
// Stretched Words
// Write a function that takes a string, and returns a new string with any duplicate consecutive letters removed.
// Examples
// unstretch("ppoeemm") ➞ "poem"
// unstretch("wiiiinnnnd") ➞ "wind"
// unstretch("ttiiitllleeee") ➞ "title"
// Longest Word
// Write a function that finds the longest word in a sentence and returns it.
// If two or more words are the biggest, return the word closest to the start of the sentence.
// Characters such as apostrophe, commas, periods, etc count as letters (e.g.O'Connor is 8 characters long).
// Examples
// longestWord("Hello darkness my old friend") ➞ "darkness"
// longestWord("Hello there mate") ➞ "Hello"
// https://edabit.com/challenge/Mc6Xi4PRw7fDzeMDB
// Create a function that takes a string and returns a string in which each character is repeated once.
// Examples
// doubleChar("String") ➞ "SSttrriinngg"
// doubleChar("Hello World!") ➞ "HHeelllloo WWoorrlldd!!"
// Hiding the Card Number
// Write a function that takes a credit card number and only displays the last four characters.
// The rest of the card number must be replaced by ************.
// Examples
// cardHide("1234123456785678") ➞ "************5678"
// cardHide("8754456321113213") ➞ "************3213"
// Move Capital Letters to the Front
// Create a function that moves all capital letters to the front of a word.
// Examples
// capToFront("hApPy") ➞ "APhpy"
// capToFront("moveMENT") ➞ "MENTmove"