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"
// Change Every Letter to the Next Letter
// Write a function that changes every letter to the next letter:
// "a" becomes "b"
// "b" becomes "c"
// "d" becomes "e"
// and so on ...
// move("hello") ➞ "ifmmp"
// Extend the Vowels
// Create a function that takes a word and extends all vowels by a number num.
// extendVowels("Hello", 5) ➞ "Heeeeeelloooooo"
// extendVowels("Edabit", 3) ➞ "EEEEdaaaabiiiit"
// extendVowels("Extend", 0) ➞ "Invalid"
// Reverse Words in a String
// Given an input string, reverse the string word by word, the first word will be the last, and so on.
// Examples
// reverseWords(" the sky is blue") ➞ "blue is sky the"
// reverseWords("hello world! ") ➞ "world! hello"