Strings
Data Types
Last Character of a string in JS.
const lastChar=(s)=>s.slice(-1)
def last_char(str):return str[-1]- const lastChar=(s)=>s.slice(-1)
describe("basic test", function(){ var domain='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', lC=(t)=>t.slice(-1); const randomString=(length, chars)=>{ var result = ''; for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)]; return result; } var rString=randomString(Math.floor(Math.random() * (domain.length - 1 + 1)) +1,domain) console.log(rString,lastChar(rString)) it ("Test passed",()=>{ Test.assertEquals(lastChar(rString), lC(rString), 'Test passed') }); });
# TODO: Replace examples and use TDD development by writing your own tests# These are some of the methods available:# test.expect(boolean, [optional] message)# test.assert_equals(actual, expected, [optional] message)# test.assert_not_equals(actual, expected, [optional] message)- describe("basic test", function(){
- var domain='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
- lC=(t)=>t.slice(-1);
- const randomString=(length, chars)=>{
- var result = '';
- for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
- return result;
- }
- var rString=randomString(Math.floor(Math.random() * (domain.length - 1 + 1)) +1,domain)
- console.log(rString,lastChar(rString))
# You can use Test.describe and Test.it to write BDD style test groupingstest.describe("Basic Test: ")test.assert_equals(last_char('python'), 'n', 'results not equal to n')test.describe("Random Test: ")test.assert_equals(last_char('nhptyo'), 'o', 'results not equal to o')- it ("Test passed",()=>{
- Test.assertEquals(lastChar(rString), lC(rString), 'Test passed')
- });
- });