본문 바로가기
알고리즘/Codewars

[Codewars] String ends with? (7 kyu) / JavaScript

by fluss 2023. 1. 2.

https://www.codewars.com/kata/51f2d1cafc9c0f745c00037d

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

Complete the solution so that it returns true if the first argument(string) passed in ends with the 2nd argument (also a string).

Examples:

solution('abc', 'bc') // returns true
solution('abc', 'd') // returns false
 
 

코드

function solution(str, ending){
  const end = str.slice(str.length - ending.length);
  if(end === ending) return true;
  return false;
}

댓글