Загрузка...

Learn Javascript | Codewars 7 kyu Season 2 - Last Digits of a Number

Welcome back to another exciting Codewars Kata run through! In today's video, we'll be solving a JavaScript challenge that requires us to implement a function called lastDigit which returns the last D digits of an integer N as a list. ? Problem Statement: Our job is to implement a function which returns the last D digits of an integer N as a list. ? Special cases: If D is greater than (the number of digits of N), return all the digits. If D is less than or equal to 0, return an empty list. ? Examples: N = 1, D = 1, result = [1] N = 1234, D = 2, result = [3, 4] N = 637547, D = 6, result = [6, 3, 7, 5, 4, 7] ? Solution: In this video, we'll walk you through a concise and elegant solution in JavaScript: We're going to convert the integer n to a string and then use the spread operator to create an array of its digits. Use the map() function to convert each digit back to a number. Use the splice() function to extract the last d digits from the array. ? Related Playlist: 7 Kyu Season 2 Playlist: https://www.youtube.com/playlist?list=PLktFju7xyBzQKR6ACPNZiTjn6pkZzikF5 Make sure to like, share, and subscribe for more coding tutorials and challenges! If you have any questions, leave a comment below, and we'll be happy to help. Happy coding! ? #algorithm #codewars #coding #learntocode #learnprogramming #javascript #learnjavascript #frontend #frontenddeveloper #programming #programminglife #computer #computerscience #computers #homework #learning #tutorial #programmingtutorials #programmingtutorial #javascripttutorial #javascripttutorialforbeginners #javascripttutorials #kata #code #codes #beginners #beginner #howto #howtocode #learningjavascript #codingtutorials #codingtutorial #learn2code | #splice #unary #plus #spread #syntax #map #array

Видео Learn Javascript | Codewars 7 kyu Season 2 - Last Digits of a Number автора JS Визионер
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки