Check if a string ends with the given target string

Declarative Approach
<script>
alert(confirmEnd("Go was designed with parallel and concurrent processing in mind", "mind"));  // true
alert(confirmEnd("Go was designed with parallel and concurrent processing in mind", "brain")); // false
alert(confirmEnd("Go was designed with parallel and concurrent processing in mind", "d"));     // true
alert(confirmEnd("Go was designed with parallel and concurrent processing in mind", "D"));     // false

function confirmEnd(str, target) {
  return str.slice(str.length - target.length) === target;
}
</script>
Most Helpful This Week