I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
where arr[i] is a string and 13 a number, so d is a string and arr[i] will become an empty string
you are only just working with spaces and letters, where in the tests there are some punctuation characters, where those are the corrisponding arr[i] will just be undefined
you will need to fix these, and then console.log() the hell out of each variable to be sure that everything is what you want to be at every step.