JAVASCRIPT   21

while.js

Guest on 12th January 2022 12:13:17 AM

  1. 'use strict'
  2.  
  3. module.exports = function (a, b) {
  4.   if (Array.isArray(a)) {
  5.     return a[a.length - 1] === b;
  6.   }
  7.  
  8.   a = String(a);
  9.   b = String(b);
  10.  
  11.   var i = b.length;
  12.   var len = a.length - i;
  13.  
  14.   while (i--) {
  15.     if (b.charAt(i) !== a.charAt(len + i)) {
  16.       return false;
  17.     }
  18.   }
  19.   return true;
  20. };

Raw Paste


Login or Register to edit or fork this paste. It's free.