How to check whether one string is rotation of another string in JS.

How to check whether one string is rotation of another string in JS.

Azhar Techno Coder

2 месяца назад

86 Просмотров

How to check whether one string is rotation of another string in JS.

Code:
str = "Azhar"

//output = rAzha = true
//arAzh = true
//ahrAz = false


function isRotation(str1,str2){
if(str1.length !== str2.length){
return false
}

for(let i=0;i(less than)str1.length;i++){
let rotation = str1.slice(i)+str1.slice(0,i)
//console.log(rotation)
if(rotation==str2){
return true
}
}

return false
}
console.log(isRotation("Azhar","arAzh"))
console.log(isRotation("Azhar","rAzha"))
console.log(isRotation("Azhar","ahrAz"))

Next Steps :

---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------
Must Watch Playlists

► 1. Javascript - https://youtube.com/playlist?list=PLO2l2fYgN805CokP5kaOWOhqP3-2vyXdS
► 2. Puppetter - https://youtube.com/playlist?list=PLO2l2fYgN805E5fbSnvtFM3K9c92ePS8e
► 3. Cypress - https://youtube.com/playlist?list=PLO2l2fYgN807KRpLfvvrqa1MSX8XdYxkV
► 4. Tech works - https://www.youtube.com/watch?v=ZNAdt4Oe5Sw&list=PLO2l2fYgN807CQ5H3ER__7x7LeEA10T2Z
► 5. Vbscript Basics To Advanced - https://www.youtube.com/watch?v=z_ctZDolyG0&list=PLO2l2fYgN805CuD-90ESrxRqX__-YJMym
► 6. Jmeter - https://youtube.com/playlist?list=PLO2l2fYgN806eNr5cr-TMTX8xGTW7Mtcn
► 7. Excel - https://youtube.com/playlist?list=PLO2l2fYgN806piZ2fD0bYNi3ExoPJlcqj
► 8. Appium - https://www.youtube.com/playlist?list=PLO2l2fYgN806V_9-wL-dpmrGg8dhPPONK
► 9. Shares - https://youtube.com/playlist?list=PLO2l2fYgN806ySmKp3sskJW0ByJalmPE2
► 10. Javascript Interview Questions -https://youtube.com/playlist?list=PLO2l2fYgN807uZl7Mp7ESavluzVU25ux9
► 11. C# Tutorials - https://www.youtube.com/playlist?list=PLO2l2fYgN805Dct9KbYNYC8nGOzwKjklt
► 12. HTML & CSS - https://www.youtube.com/playlist?list=PLO2l2fYgN804tkFuKw9DlcVXT0m8hDzdw
► 13. Browser Console - https://www.youtube.com/playlist?list=PLO2l2fYgN80692hfTP1BcgmWNBZV0ZYzo
► 14. JSON - https://www.youtube.com/playlist?list=PLO2l2fYgN8062RQNrQt5xAQZFaFINvMsY
► 15. Specflow - https://www.youtube.com/playlist?list=PLO2l2fYgN806s2KXmhI6eqHLwP_sriPl0
► 16. MongoDB - https://www.youtube.com/playlist?list=PLO2l2fYgN80626nl1UkUz3ufXSlgMXIkh
► 17. Postman - https://youtube.com/playlist?list=PLO2l2fYgN804Nf9Vfma54yFNwlA3bF9-Z
► 18. Python - https://youtube.com/playlist?list=PLO2l2fYgN80486BcimGYi9Y3XQ-beQHCN
► 19. Typescript - https://www.youtube.com/playlist?list=PLO2l2fYgN805MyyI2Q1YpkX78OehOqzDg
► 20. Node - https://www.youtube.com/playlist?list=PLO2l2fYgN807v_icJITbdYV_IP5wdgDIy
► 21. Java Selenium Interview Questions: https://www.youtube.com/playlist?list=PLO2l2fYgN806mr2M9Km0KNQz_wv_tZTwD
► 22. Real Time Interview Q & A: https://www.youtube.com/playlist?list=PLO2l2fYgN805uI-sDXvo0jV6qvXWHi6x8
► 23.SOAP UI Tutorials :https://www.youtube.com/playlist?list=PLO2l2fYgN807YvgfwfRCVM9e0mepllR-n
► 24. WebDriverIO : https://www.youtube.com/watch?v=4kG8V_Q0HZg&list=PLO2l2fYgN807WMv5p67llcQ1iHPNaDYDt
► 25. Jenkins :https://www.youtube.com/watch?v=NCFJjwWj90s&list=PLO2l2fYgN8071gSZAuy74zxXI7MyqJTUR
► 26. Cloud and CyberSecurity : https://www.youtube.com/watch?v=OcG5xysM1Jw&list=PLO2l2fYgN805iX8fmlYN6mkbUsVGkTnuP
► 27. GitHub :https://www.youtube.com/watch?v=jWS9kwDsSZQ&list=PLO2l2fYgN805n5v0ltpqIhFlgBt-S-GcI
► 28. Videos on Ubuntu : https://youtube.com/playlist?list=PLO2l2fYgN807KGgSxWZfKMH2tPCH5Vngv&si=5fdXad0zdF7oMmCr
► 29. Videos on Beyond Jira : https://youtube.com/playlist?list=PLO2l2fYgN805vq85j70sjEjAlByrZV4r5&si=sx0P1_qT75VR7jpW
---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------

#javascript
#rotation
#javascriptprogramming

Тэги:

#How_to_check_whether_one_string_is_rotation_of_another_string_in_JS. #javascript #find_if_one_string_is_a_rotation_of_another_string #check_whether_one_string_is_a_rotation_of_another_string #string_rotation #rotation_of_string ##rotation_of_a_list_in_python #check_whether_strings_are_rotation_of_each_other_by_javascript #rotation #circular_array_rotation_javascript #important_question_of_javascript #rotate_string_leetcode_in_java
Ссылки и html тэги не поддерживаются


Комментарии: