Surrogate pair check

Report a typo

Write a JavaScript function that checks whether a given character has surrogate pairs to represent it. The function should return true if the character requires surrogate pairs, and false if it doesn't.

Sample Input 1:

🐇

Sample Output 1:

true
Write a program in JavaScript
const readline = require('readline');

/* Do not change code above */

function hasSurrogatePairs(char) {
//Write your code here
}

/* Do not change code below */

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
encoding: 'utf16le',
});

let character = '';
rl.input.on('data', (data) => {
character += data;
});

rl.on('close', () => {
console.log(hasSurrogatePairs(character));
});

rl.question('', () => {
rl.close();
});
___

Create a free account to access the full topic