Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reverse(str){
- let output = ""
- for(let i = stirng.length - 1; i >= 0; i--){
- output += str[i]
- }
- return output
- }
- function containsChar(haystack, needle){
- for(let i = 0; i < haystack.length; i++){
- let currentCharacter = haystack[i]
- if(currentCharacter == needle){
- return true
- }
- }
- return false
- }
- function indexOfChar(haystack, needle){
- for(let i = 0; i < haystack.length; i++){
- let currentCharacter = haystack[i]
- if(currentCharacter == needle){
- return i
- }
- }
- return -1
- }
- function removeChar(str, char){
- let output = ""
- for(let i = 0; i < str.length; i++){
- let currentCharacter = str[i]
- if(currentCharacter != char){
- output += currentCharacter
- }
- }
- return output
- }
- function replaceChar(str, char){
- let output = ""
- for(let i = 0; i < str.length; i++){
- let currentCharacter = str[i]
- if(currentCharacter != char){
- output += currentCharacter
- }else{
- output += char
- }
- }
- return output
- }
- function substring(str, start, stop){
- let output = "";
- for(let i = start; i < stop; i++){
- output += str[i]
- }
- return output
- }
- function contains(haystack, needle){
- for(let i = 0; i < haystack.length; i++){
- let match = true
- for(let j = 0; j < needle.length; j++){
- let haystackCharacter = haystack[i+j]
- let needleCharacter = needle[j]
- if(haystackCharacter != needleCharacter){
- match = false;
- break;
- }
- }
- if(match){
- return true
- }
- }
- return false;
- }
- function contains(haystack, needle){
- for(let i = 0; i < haystack.length; i++){
- let haystackString = substring(haystack, i, i+needle.length)
- if(haystackString == needle){
- return true
- }
- }
- return false;
- }
- function remove(haystack, needle){
- let output = ""
- for(let i = 0; i < haystack.length; i++){
- let match = true
- for(let j = 0; j < needle.length; j++){
- let haystackCharacter = haystack[i+j]
- let needleCharacter = needle[j]
- if(haystackCharacter != needleCharacter){
- match = false;
- break;
- }
- }
- if(match){
- i += needle.length-1
- }else{
- output += haystack[i]
- }
- }
- return output
- }
- function remove(haystack, needle){
- let output = ""
- for(let i = 0; i < haystack.length; i++){
- let haystackSubstring = substring(haystack, i, i + needle.length - 1)
- if(haystackSubstring == needle){
- i += needle.length-1
- }else{
- output += haystack[i]
- }
- }
- return output
- }
- function replace(haystack, needle, replaceWith){
- let output = ""
- for(let i = 0; i < haystack.length; i++){
- let match = true
- for(let j = 0; j < needle.length; j++){
- let haystackCharacter = haystack[i+j]
- let needleCharacter = needle[j]
- if(haystackCharacter != needleCharacter){
- match = false;
- break;
- }
- }
- if(match){
- i += needle.length-1
- output += replaceWith
- }else{
- output += haystack[i]
- }
- }
- return output
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement